Is there any particular reason why #pragma once doesn't seem to be used in Arduino code? Is this just because it's not a well-known feature, or is there some overriding reason to use #ifndef XXX_H/#define XXX_H/#endif?
Asked
Active
Viewed 8,243 times
7
Tim Long
- 305
- 3
- 12
1 Answers
9
#pragma once operates on the absolute filename of a file. Include guards work on the content of the file.
If you have multiple copies of the same library (maybe one library has some parts of another included in it - it happens...) #pragma once would have no hope of working right.
Add to that the fact that the Arduino IDE copies some files around the place when building and '#pragma once is pretty much screwed.
Include guards work regardless. So sensible people use include guards and shun #pragma once.
Majenko
- 105,761
- 5
- 80
- 138