I've searched SO, but haven't found an answer to this specific questions. Forgive me if it's already been answered.
If you have the following:
#define MACRO 40
You don't assign it to a variable you use it in a loop:
for(int i = 0; i < MACRO; i++) {...
The perprocessor then creates:
for(int i = 0; i < 40; i++) {...
Would the compiler then implicitly cast it to an int since the comparison is with type int i
? I've looked at this question Type of #define variables, and quite a few answers down Edgar Bonet implies that there is an order in which the compiler chooses how to treat the macro?
This question, How does C++ implicitly cast arguments to a comparator such as <?, was also suggested, but only describes how implicit casting works with a comparison with two types. Since a macro doesn't really have a type I'm not sure if this applies.
See Question&Answers more detail:os