- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi. I'd like to use "#pragma once" in my .h files instead of the old fashioned #ifndef __FOO.H include guards,
It seems to work, but I get the warning symbol and the complaint "#pragma once in main file" in the left margin of the editor, although there are no actually compiler warnings.
Anyone know if this is OK to use, and if so, how to get rid of the warning in the editor?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Since there is no compiler warning it will not effect the functioning of application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why do you want to get rid of the #ifdefs? Using #pragma once doesn't speed up the compiling.
Are you using the Keil compiler (for PsoC3) or gcc? This might actually be a bug in the syntax checker of Creator (I think its using LLVM under the hood for that).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nope, I'm using the built-in PSoC 4 ARM compiler, not Keil.
I've used the #ifndef guards for years too, but I'm trying to modernize my use of C a little, and those guards are ugly. It's much nicer to just stick "#pragma once" on the first line of every .h file and not worry about accidentally closing the #ifndef, etc. Pure aesthetics.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Then you should raise a support case with Cypress.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Since there is no compiler warning it will not effect the functioning of application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We support C99 and #pragma once is not part of that definition. As a result we are reticent about enabling it. Our roadmap includes support for more third party software tools and so we're a bit wary of investing in non-standard extensions.
I agree that the #ifndef method is uglier, of course, and so I hope you are OK living with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, I guess I can do that. Although it's pretty well supported for a nonstandard #pragma, including by the ARM compiler, Keil (http://www.keil.com/support/man/docs/armclang_ref/armclang_ref_chr1359124989221.htm) and IAR. Although ARM doesn't recommend it, most books on modern C programming do.
Portability (from Wikipedia page on #pragma once:
Clang Supported[7]
Comeau C/C++ Supported[8]
C++Builder XE3 Supported[9]
Digital Mars C++ Supported[10]
GCC Supported[11] (since 3.4[5])
HP C/aC++ Supported[citation needed] (since at least A.06.12)
IBM XL C/C++ Supported[12] (since 13.1.1)
Intel C++ Compiler Supported[13]
Microsoft Visual C++ Supported[14] (since 4.2)
Pelles C Supported[15]
ARM DS-5 Supported[16]
IAR C/C++ Supported[17]
Oracle Developer Studio C/C++ Supported[18] (since 12.5)
Portland Group C/C++ Not supported[19]