Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 179209 - "#pragma once" support in header files
"#pragma once" support in header files
Status: RESOLVED DUPLICATE of bug 194887
Product: cnd
Classification: Unclassified
Component: -- Other --
PC Windows XP
: P3 with 1 vote (vote)
: 7.2
Assigned To: Vladimir Voskresensky
Depends on:
  Show dependency treegraph
Reported: 2010-01-04 22:55 UTC by rwerp
Modified: 2012-09-03 07:28 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description rwerp 2010-01-04 22:55:04 UTC
It would be nice to be able to ask Netbeans to insert

#pragma once

instead of or before the

#ifndef _FOOBAR_H
#define _FOOBAR_H

// code

#endif /* _FOOBAR_H */

in new header files.
Comment 1 Vladimir Voskresensky 2010-01-07 05:49:58 UTC
you can always modify template for header files yourself :-)
The question if code assistance correctly understands #pragma once (I think it doesn't)
Comment 2 Vladimir Voskresensky 2010-01-07 05:51:47 UTC
To modify templates: Tools->Templates->C++->Header file
choose Open In Editor, modify file, save it => newly created files will have content as you changed it
Comment 3 rwerp 2010-01-07 08:19:10 UTC
Thanks, I'm a muppet :)
Comment 4 Vladimir Voskresensky 2010-01-09 10:14:55 UTC
btw, if you are interested 'pragma once' is obsolte. From preprocessor spec:
There is also an explicit directive to tell the preprocessor that it need not include a file more than once. This is called `#pragma once', and was used in addition to the `#ifndef' conditional around the contents of the header file. `#pragma once' is now obsolete and should not be used at all. 
Comment 5 rwerp 2010-01-09 10:21:16 UTC
It was "un-obsoleted" in newere versions of gcc:

"Another way to prevent a header file from being included more than once is with the `#pragma once' directive. If `#pragma once' is seen when scanning a header file, that file will never be read again, no matter what.

`#pragma once' does not have the problems that `#import' does, but it is not recognized by all preprocessors, so you cannot rely on it in a portable program."
Comment 6 Vladimir Voskresensky 2010-01-09 11:16:28 UTC
Thanks for the link. 
So, we need to support it if we don't
Comment 7 soldatov 2010-01-09 12:00:03 UTC
Sun Studio doesn't recognize "#pragma once"

#include "test.h"
#include "test.h"
int main() {
  return 0;
#pragma once

int f(){
 return 0;
sova@sova:~$ gcc test.c 
sova@sova:~$ cc test.c 
"test.h", line 3: identifier redefined: f
	current : function() returning int
	previous: function() returning int : "test.h", line 3
cc: acomp failed for test.c
Comment 8 shirojirou 2011-12-13 06:26:35 UTC
I wonder if Netbeans have a plan to recognize "#pragma once".

Our project uses "once", so it takes very long time to analyze project...
Comment 9 Vladimir Voskresensky 2011-12-13 06:42:14 UTC
(In reply to comment #8)
> I wonder if Netbeans have a plan to recognize "#pragma once".
It is supported (see issue #194887).
What is your version of NB?

Have you tried to give more memory to NB (-J-Xmx2G as netbeans param in command line)? Or use 32bit JVM?
Comment 10 Vladimir Voskresensky 2011-12-13 06:42:25 UTC

*** This bug has been marked as a duplicate of bug 194887 ***
Comment 11 shirojirou 2012-05-23 03:56:01 UTC
I think this is not resolved yet.

For example

#ifdef ABCD_AAA
#define ABCD_BBB
#define ABCD_AAA

#include "test.h"
#include "test.h"


If I add include guard to test.h, a code completion indicates 
only ABCD_AAA.

But if I use #pragma once instead of include guard in test.h,
the code completion indicates both definition.

I know #pragma once is not portable, but my project has it.
Please check this.
Comment 12 Vladimir Voskresensky 2012-09-03 07:28:37 UTC
Looks like a recent regression in 7.2 (see issue #217711)

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo