News for hackers. Stuff that matters.
Re:Dangerous Embedded C Coding Standard Rules (2011) by Nursie on Monday December 30, 2013 @12:16PM (#6985524)
Macros enable you to replace things at compile time.

The C preprocessor is a powerful and awesome thing by itself and I miss it when it's not available in other languages. It enables you to do things like pass line and file numbers automatically. For instance -

    #define log_message(format...) _log_message(__FILE__, __LINE__, format)
    void _log_message(char* filename, int line, char* format, ...);
And there's nothing inherently wrong with #define for frequently used magic numbers. They have the advantage of being pre-processed out rather than being separate variables at compile time.

Macros are also useful to simplify little repeated chunks of code that don't really need their own function.

I've not often seen macros used to try to speed up code.

--edit-- I don't know how long you've kept up with your C, but what you've realised after a year with the language doesn't seem as obvious to me after 15.

There are no comments on this comment yet.