Start your FREE trial of Sygic Premium today!. The idea behind Sygic is simple: To give our premium users a completely unique navigation experience.. Sygic premium with traffic camera real-time traffic safety and locations of mobile speed cameras .Q:
Difference between pre-compiler and compiler macros
If I want to define a macro to avoid repetition of code, what is the difference between defining it before pre-compiling the code and defining it after compiling the code?
I guess you are asking about the pre-processor macros and compiler macros?
The pre-processor is responsible for translating the "code" you write into a lower level language so that you do not have to worry about the underlying implementation details. For example, you can write a pre-processor macro to do any of the following:
If you use the above macros to print the number of times they have been invoked then you can see that the order of the parameters in the printf does not matter. The compiler will deal with the parameters as they were passed and ignore the pre-processor macro.
Now in case of the compiler macros, this is usually used to define some "constant" definitions for the compiler. This is very useful because it allows us to just define the macro once and the compiler will make sure that the same constant definition is available to each compilation unit or source file in the program.
This is one of the biggest problems of C that the code is not portable as it depends upon the definitions of the const keyword. But if you use the compiler macros you do not have to worry about that because the definitions are guaranteed to be available to each compilation unit.