here C programming Guidelines and coding standards says we have to avoid magic numbers from program and use macro for magic numbers
In Macro it will take more time to evaluate as compare to Constants so performance is more better in magic numbers or constants.
for Example
for(i=0;i<255;i++)
{
}
We use this
#define MAX 255
for(i=0;i<MAX;i++)
{
}
Second one is take more time compare to first one so why we prefer second one as per coding standards.
using a macro constant doesn’t take more time. the
#defineis a preprocessor instruction, so in the binary code, the two pieces of code will compile to the same thing!However, we avoid using ‘magic numbers’ for reasons of maintainability, assume you have many loops and arrays of the same size, if this size changes in the future, you will need to search the code and change it everywhere, [and only it!] while if you use a preprocessor command, you will need to change only it [the preprocessor command].