3 ms·
Feature/Trick #4 : #ifndef FILE_H #define FILE_H ... #endif How is this "Cool C Programming"? What am I missing?
by huhtenberg 13y ago
Feature/Trick #4 :
#ifndef FILE_H
#define FILE_H
...
#endif
How is this "Cool C Programming"? What am I missing?
- apaprocki 13y agoIt might as well talk about #pragma once if it is explaining include guards. Fun fact: Oracle (Sun) Studio doesn't support #pragma once. Instead, it actually looks for proper include guards in the header and if they exist, it optimizes away re-includes of the file if the condition is false.
- dfbrown 13y agogcc does this as well (though it also supports #pragma once). I believe the current convention is to prefer #ifndef include guards as it is more portable and most compilers can detect and avoid re-including files with them.
- ben0x539 13y agoI assumed that was common practice.
- apaprocki 13y agoNope, and to make matters worse -- IBM xlC doesn't optimize at the include sites. So adding include-site guards actually speeds up compilation times in a non-insignificant way. e.g., #ifndef FOO_H #include <foo.h> #endif
- ExpiredLink 13y agoYou don't miss anything. Cool C Preprocessor Programming isn't Cool C Programming.
- intull 13y agoThis talk was actually meant for beginners and for those who were acquainted with C to some extent. Furthermore, many never learn about the preprocessor features (at least here in India) and I ended up explaining things in detail which made up a majority of the post. I know it feels as if there was a prime focus on the preprocessor, but that wasn't the idea. It just took longer to explain those features (at least for beginners).