C programming bugs with macros

preview_player
Показать описание
In last week’s video, I showed how you can use a macro to help optimize a DOS program. Macros are a pretty standard way to do that. Similar to inline functions, the macro is a great way to replace simple 1-line functions. But sometimes you need to use a macro instead of an inline function.

Macros are great, but you need to be careful. Let’s look at an example where things break.

Visit our website

Join us on Facebook

Follow us on Twitter

Consider supporting me on Patreon

And don't forget to Like and Subscribe!

Standard comment rules apply.
Рекомендации по теме
Комментарии
Автор

For someone who doesn't know how macro works this may lead him to pull off his hair.
Please do more videos like this,
Thanks Jim.

ahmad-murery
Автор

To see how preprocessor expands all those macros you can run the command
> i16gcc -E -o max1.c max.c
and look at the bottom of the resulting `max1.c` file.

platoek
Автор

I would never increment count inside of a function call (4:32 min). This is difficult to read code. I would put count++ in the next line. This is much less error prone and the compiler will probably also be able to optimize that better.
So thank you for showing us that trap but in real life it wouldn't happen to me, because i do not increment a value inside of a function call.

BTW, i tested your code by using an inline function that was added to C99 with a static or a extern keyword instead of a macro and with an inline function it works. I didn't check what kind of assembler code the compiler generates. gcc version was 10.2.1 on a Debian Linux system.

OpenGLever
Автор

Hello! Where is the proper place to discuss possible bugs in FreeDOS _packages_? I have an issue with the VIM package.

platoek
Автор

Hey can you still use 6502 assembly for modern devices

DV-yexb