It's a good practice because
- the array size obviously has to be hard-coded
- but it shouldn't have a magic number injected directly into the source code
- therefore, a macro is a good way to give it a readable name and remove it from the source
That being said I'm not sure I agree this is the best way. An enum also works and avoids some of the problems with macros (e.g. harder to overwrite and silently compile). And IIRC a const int
works as well.
For reference this compiles with cc
:
const int s = 1;
int a[s];
int main() {
return 0;
}
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix