Electronics > Microcontrollers

Stupid debugging of macro values

<< < (3/3)

dcarr:
Hack:
Add another #define that redefines the previous macro.
Gcc will spit out an error that helpfully includes the previous macro value.

Doctorandus_P:
Macro's in C a bit of a weird thing, but they can make code a lot more readable, but also harder to debug.
One important thing to always remember with macro's is that it is not a language thing, but only a text substitution feature.

I've stopped using a C compiler a long time ago, but compile all C code with a C++ compiler.
C++ has better error checking and a lot of extra features.

Most of the old C macro's can be rewritten as C++ compile time constants. If you do this, you can even call a function to initialize your constant, and if that function is not used elsewhere, it won't even get included in the binaries. Your compile time constant also has a real type.

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod