4 ms·
Tangential question: why aren't we using '#pragma once' more? I've adopted it in personal stuff and it's obviously Good. Is anyone still really coding for some
by nothrabannosir 10y ago
Tangential question: why aren't we using '#pragma once' more? I've adopted it in personal stuff and it's obviously Good. Is anyone still really coding for some arcane compiler that doesn't support it? Or is there some good reason for not just switching?
- Sir_Cmpwn 10y agoIt's not standard. There are more compilers out there than gcc and clang.
- maccard 10y agoWhat compilers don't support it?
- slavik81 10y agoThe Portland Group's compiler (PGI) is the only modern compiler I know of, but there's probably a few embedded system compilers too.
- Sir_Cmpwn 10y agoOne compiler I've encountered is SDCC. But think about new compilers - they shouldn't have to implement non-standard features to compile portable C. #pragma is non-portable.
- nanolith 10y agoThere are proprietary compilers for embedded chipsets that don't support this feature. Granted, these are fewer and further between than they once were, but they are out there. It really depends on how portable you want your code to be. Even though it is widely supported, it still isn't a standard language feature. If your goal is to have a library that runs on most Unix-like and Windows systems, then '#pragma once' works just fine. But, if there's a possibility that your code would be deployed to an odd platform, it's probably best to use traditional header guards. I'm so used to using header guards that the appeal of '#pragma once' isn't that great for me.
- apaprocki 10y agoYou don't have to go that far.. Oracle Studio (nee Sun Studio) for Solaris doesn't support it.
- loeg 10y ago#pragma once is great. I use it in new code. Clang and GCC both support it, don't know about other compilers.
- TheNewAndy 10y ago1 - it isn't obvious what it does (if a file has a symbolic link, then is the link the same file? what about a hard link?) 2 - it offers no performance benefit on sensible compilers (which have a special case in them that can detect the typical header guard pattern and so avoid reading a header twice) 3- it is non standard, and the feature it provides is one which is easily implemented within the standard, where the only disadvantage seems to be that you need to type more characters.
- babuskov 10y agoCan't say about the others, but my IDE just adds #ifndef/#endif automatically, so I don't bother to change it manually. Is there some performance gain from #pragma once ?
- slavik81 10y agoDoes it update automatically when you copy and/or rename files? > Is there some performance gain from #pragma once? No. Include guards can be detected and optimized just the same.
- babuskov 10y ago> Does it update automatically when you copy and/or rename files? IIRC, it does only if I use the Refactor option inside the IDE.