By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,368 Members | 1,706 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,368 IT Pros & Developers. It's quick & easy.

#pragma once in ISO standard yet?

P: n/a

I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?

Thanks...
Dec 12 '07 #1
Share this Question
Share on Google+
26 Replies


P: n/a
Rick <re****************@spam.nowrote in
news:h9********************************@4ax.com:
>
I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?

If it's either language it would be C++.

Try asking in comp.std.c++

--
Tomás Ó hÉilidhe
Dec 12 '07 #2

P: n/a
Rick wrote:
I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?

Thanks...
No, it is not in the standard. Many compilers implement this
but it is not (yet) standard

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Dec 12 '07 #3

P: n/a
Rick wrote:
I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?
You have been told wrong for C.

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Dec 12 '07 #4

P: n/a
Rick wrote:
I'm told that "#pragma once" has made it into the ISO
standard for either C or C++.
Did you mean neither? It isn't in C. I doubt it's in C++.
I can't find any reference to that anywhere.
Ask the person who told you to supply evidence.

jacob navia <ja...@nospam.comwrote:
No, it is not in the standard. Many compilers implement
this but it is not (yet) standard
Because many compilers implement it differently. The normal
include guard mechanism may be klunky, but at least the
programmer always knows _exactly_ what the preprocessor can
and will do with it.

--
Peter
Dec 13 '07 #5

P: n/a
Rick wrote:
>
I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?
For example, from N869.txt:

[1] c:\stds>cat n869.txt | grep -n #pragma
9468: #pragma STDC FP_CONTRACT on-off-switch
9469: #pragma STDC FENV_ACCESS on-off-switch
9470: #pragma STDC CX_LIMITED_RANGE on-off-switch
9588: #pragma listing on "..\listing.dir"
10114: #pragma STDC CX_LIMITED_RANGE on-off-switch
11136: #pragma STDC FENV_ACCESS on-off-switch
11179: #pragma STDC FENV_ACCESS ON
11192: placed invocation of #pragma STDC FENV_ACCESS ON.165)
11208: #pragma STDC FENV_ACCESS ON pragma, and assuming the
11338: #pragma STDC FENV_ACCESS ON
11405: #pragma STDC FENV_ACCESS ON
11526: #pragma STDC FENV_ACCESS ON
12343: #pragma STDC FP_CONTRACT on-off-switch
24253: #pragma STDC CX_LIMITED_RANGE on-off-switch
24349: #pragma STDC FENV_ACCESS on-off-switch
24452: #pragma STDC FP_CONTRACT on-off-switch
25641: #pragma STDC FENV_ACCESS ON
25680: #pragma STDC FENV_ACCESS ON
25752: #pragma STDC FENV_ACCESS ON
26310: #pragma STDC FENV_ACCESS ON
26461: #pragma STDC FENV_ACCESS ON
26514: #pragma STDC FENV_ACCESS ON
26564: #pragma STDC FENV_ACCESS ON
26825: #pragma STDC FP_CONTRACT OFF
26888: #pragma STDC FP_CONTRACT OFF
27783: -- An unrecognized #pragma directive is encountered
28363: -- A non-STDC #pragma preprocessing directive that is
28367: -- A #pragma STDC preprocessing directive does not match
29051: -- The behavior on each recognized non-STDC #pragma
29522: #pragma preprocessing directive, 6.10.6

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Dec 13 '07 #6

P: n/a
jacob navia wrote:
Rick wrote:
>I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?

No, it is not in the standard. Many compilers implement this
but it is not (yet) standard
Wrong. It is in the C99 standard.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Dec 13 '07 #7

P: n/a
CBFalconer <cbfalco...@yahoo.comwrote:
jacob navia wrote:
Rick wrote:
I'm told that "#pragma once" has made it into the
ISO standard for either C or C++. I can't find any
reference to that anywhere. ...
No, it is not in the standard. Many compilers implement
this but it is not (yet) standard

Wrong. It is in the C99 standard.
Chapter and verse, please.

Note the OP is talking specifically about #pragma once, not
merely #pragma.

--
Peter
Dec 13 '07 #8

P: n/a
CBFalconer wrote:
Rick wrote:
>I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?

For example, from N869.txt:

[1] c:\stds>cat n869.txt | grep -n #pragma
What the OP wanted was more like

grep "#pragma" n869.txt | grep once

Which outputs a whole not of nothing....

--
Ian Collins.
Dec 13 '07 #9

P: n/a
CBFalconer wrote:
jacob navia wrote:
>Rick wrote:
>>I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?
No, it is not in the standard. Many compilers implement this
but it is not (yet) standard

Wrong. It is in the C99 standard.
Since all the C99 standard pragmas begin with
#pragma STDC
it is very difficult for
#pragma once
to be a C99 standard pragma. Would you care to share _where_ in the
standard you think this is? There are only three standard pragmas,
FP_CONTRACT, FENV_ACCESS, and CX_SELECTED_RANGE. None of them is
spelled "once".
Dec 13 '07 #10

P: n/a
CBFalconer wrote:
Rick wrote:
>I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?

For example, from N869.txt:

[1] c:\stds>cat n869.txt | grep -n #pragma
9468: #pragma STDC FP_CONTRACT on-off-switch
9469: #pragma STDC FENV_ACCESS on-off-switch
9470: #pragma STDC CX_LIMITED_RANGE on-off-switch
9588: #pragma listing on "..\listing.dir"
10114: #pragma STDC CX_LIMITED_RANGE on-off-switch
11136: #pragma STDC FENV_ACCESS on-off-switch
11179: #pragma STDC FENV_ACCESS ON
11192: placed invocation of #pragma STDC FENV_ACCESS ON.165)
11208: #pragma STDC FENV_ACCESS ON pragma, and assuming the
11338: #pragma STDC FENV_ACCESS ON
11405: #pragma STDC FENV_ACCESS ON
11526: #pragma STDC FENV_ACCESS ON
12343: #pragma STDC FP_CONTRACT on-off-switch
24253: #pragma STDC CX_LIMITED_RANGE on-off-switch
24349: #pragma STDC FENV_ACCESS on-off-switch
24452: #pragma STDC FP_CONTRACT on-off-switch
25641: #pragma STDC FENV_ACCESS ON
25680: #pragma STDC FENV_ACCESS ON
25752: #pragma STDC FENV_ACCESS ON
26310: #pragma STDC FENV_ACCESS ON
26461: #pragma STDC FENV_ACCESS ON
26514: #pragma STDC FENV_ACCESS ON
26564: #pragma STDC FENV_ACCESS ON
26825: #pragma STDC FP_CONTRACT OFF
26888: #pragma STDC FP_CONTRACT OFF
27783: -- An unrecognized #pragma directive is encountered
28363: -- A non-STDC #pragma preprocessing directive that is
28367: -- A #pragma STDC preprocessing directive does not match
29051: -- The behavior on each recognized non-STDC #pragma
29522: #pragma preprocessing directive, 6.10.6
I don't see "#pragma once" anywhere in that list. If my eyes are
deceiving me, could you do something to make the location of the word
"once" more obvious?

Dec 13 '07 #11

P: n/a
On Wed, 12 Dec 2007 16:07:38 -0500, Rick <re****************@spam.no>
wrote in comp.lang.c:
>
I'm told that "#pragma once" has made it into the ISO standard for
You've multiposted this question in several groups over the past 24
hours.

Who told you this? What qualifications to they have that you should
believe them? If they are so knowledgeable, can't they provide you
with a reference?
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?
No, it's not true.
Thanks...
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Dec 13 '07 #12

P: n/a
Martin Ambuhl wrote:
CBFalconer wrote:
>jacob navia wrote:
>>Rick wrote:

I'm told that "#pragma once" has made it into the ISO standard
for either C or C++. I can't find any reference to that
anywhere. If it's true, do any of you have a reference I can use?

No, it is not in the standard. Many compilers implement this
but it is not (yet) standard

Wrong. It is in the C99 standard.

Since all the C99 standard pragmas begin with
#pragma STDC
it is very difficult for
#pragma once
to be a C99 standard pragma. Would you care to share _where_ in the
standard you think this is? There are only three standard pragmas,
FP_CONTRACT, FENV_ACCESS, and CX_SELECTED_RANGE. None of them is
spelled "once".
I extracted all occurences of "#pragma" in N869 in another
article. If you really want the " once" part it is missing, but
the data is there.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Dec 14 '07 #13

P: n/a
James Kuyper wrote:
>
CBFalconer wrote:
Rick wrote:
I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?
For example, from N869.txt:

[1] c:\stds>cat n869.txt | grep -n #pragma
9468: #pragma STDC FP_CONTRACT on-off-switch
9469: #pragma STDC FENV_ACCESS on-off-switch
9470: #pragma STDC CX_LIMITED_RANGE on-off-switch
9588: #pragma listing on "..\listing.dir"
10114: #pragma STDC CX_LIMITED_RANGE on-off-switch
11136: #pragma STDC FENV_ACCESS on-off-switch
11179: #pragma STDC FENV_ACCESS ON
11192: placed invocation of #pragma STDC FENV_ACCESS ON.165)
11208: #pragma STDC FENV_ACCESS ON pragma, and assuming the
11338: #pragma STDC FENV_ACCESS ON
11405: #pragma STDC FENV_ACCESS ON
11526: #pragma STDC FENV_ACCESS ON
12343: #pragma STDC FP_CONTRACT on-off-switch
24253: #pragma STDC CX_LIMITED_RANGE on-off-switch
24349: #pragma STDC FENV_ACCESS on-off-switch
24452: #pragma STDC FP_CONTRACT on-off-switch
25641: #pragma STDC FENV_ACCESS ON
25680: #pragma STDC FENV_ACCESS ON
25752: #pragma STDC FENV_ACCESS ON
26310: #pragma STDC FENV_ACCESS ON
26461: #pragma STDC FENV_ACCESS ON
26514: #pragma STDC FENV_ACCESS ON
26564: #pragma STDC FENV_ACCESS ON
26825: #pragma STDC FP_CONTRACT OFF
26888: #pragma STDC FP_CONTRACT OFF
27783: -- An unrecognized #pragma directive is encountered
28363: -- A non-STDC #pragma preprocessing directive that is
28367: -- A #pragma STDC preprocessing directive does not match
29051: -- The behavior on each recognized non-STDC #pragma
29522: #pragma preprocessing directive, 6.10.6

I don't see "#pragma once" anywhere in that list. If my eyes are
deceiving me, could you do something to make the location of the
word "once" more obvious?
Did you thing that grep would miss such an occurence? It didn't.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Dec 14 '07 #14

P: n/a
CBFalconer said:
Martin Ambuhl wrote:
>CBFalconer wrote:
>>jacob navia wrote:
Rick wrote:

I'm told that "#pragma once" has made it into the ISO standard
for either C or C++. I can't find any reference to that
anywhere. If it's true, do any of you have a reference I can use?

No, it is not in the standard. Many compilers implement this
but it is not (yet) standard

Wrong. It is in the C99 standard.

Since all the C99 standard pragmas begin with
#pragma STDC
it is very difficult for
#pragma once
to be a C99 standard pragma. Would you care to share _where_ in the
standard you think this is? There are only three standard pragmas,
FP_CONTRACT, FENV_ACCESS, and CX_SELECTED_RANGE. None of them is
spelled "once".

I extracted all occurences of "#pragma" in N869 in another
article. If you really want the " once" part it is missing, but
the data is there.
Chuck, the whole context is quoted above. The question relevant to this
group is whether "#pragma once" is part of the C Standard. It is not
disputed that #pragma is part of the Standard. You claimed that Jacob
Navia was *wrong* to say that "#pragma once" is not part of the Standard,
but you have not substantiated that claim by citing the part of the
Standard in which "#pragma once" appears - and indeed you appear to
recognise that this is not possible (because it isn't actually there).

In fact, the Standard does not define "#pragma once" at all. With the three
exceptions that Martin Ambuhl pointed out, the Standard doesn't define any
#pragmas whatsoever. You have therefore incorrectly "corrected" Jacob
Navia, and therefore - by the conventions of this group which you are so
quick to attempt to enforce and yet so reluctant to observe - you owe him
an apology.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Dec 14 '07 #15

P: n/a
CBFalconer wrote:
James Kuyper wrote:

CBFalconer wrote:
Rick wrote:
>I'm told that "#pragma once" has made it into the ISO standard for
>either C or C++. I can't find any reference to that anywhere. If
>it's true, do any of you have a reference I can use?
>
For example, from N869.txt:
>
[1] c:\stds>cat n869.txt | grep -n #pragma
9468: #pragma STDC FP_CONTRACT on-off-switch
9469: #pragma STDC FENV_ACCESS on-off-switch
9470: #pragma STDC CX_LIMITED_RANGE on-off-switch
9588: #pragma listing on "..\listing.dir"
10114: #pragma STDC CX_LIMITED_RANGE on-off-switch
11136: #pragma STDC FENV_ACCESS on-off-switch
11179: #pragma STDC FENV_ACCESS ON
11192: placed invocation of #pragma STDC FENV_ACCESS ON.165)
11208: #pragma STDC FENV_ACCESS ON pragma, and assuming the
11338: #pragma STDC FENV_ACCESS ON
11405: #pragma STDC FENV_ACCESS ON
11526: #pragma STDC FENV_ACCESS ON
12343: #pragma STDC FP_CONTRACT on-off-switch
24253: #pragma STDC CX_LIMITED_RANGE on-off-switch
24349: #pragma STDC FENV_ACCESS on-off-switch
24452: #pragma STDC FP_CONTRACT on-off-switch
25641: #pragma STDC FENV_ACCESS ON
25680: #pragma STDC FENV_ACCESS ON
25752: #pragma STDC FENV_ACCESS ON
26310: #pragma STDC FENV_ACCESS ON
26461: #pragma STDC FENV_ACCESS ON
26514: #pragma STDC FENV_ACCESS ON
26564: #pragma STDC FENV_ACCESS ON
26825: #pragma STDC FP_CONTRACT OFF
26888: #pragma STDC FP_CONTRACT OFF
27783: -- An unrecognized #pragma directive is encountered
28363: -- A non-STDC #pragma preprocessing directive that is
28367: -- A #pragma STDC preprocessing directive does not match
29051: -- The behavior on each recognized non-STDC #pragma
29522: #pragma preprocessing directive, 6.10.6
I don't see "#pragma once" anywhere in that list. If my eyes are
deceiving me, could you do something to make the location of the
word "once" more obvious?

Did you thing that grep would miss such an occurence? It didn't.
No, I think you responded to a question about "#pragma once" with an
answer about "#pragma". That was either pointless, or rude, depending
upon whether or not you were expecting us to do the follow-up "grep
once" that you should have performed. If you did expect it, you
compounded the rudeness by not explaining that fact.
Dec 14 '07 #16

P: n/a
Al Balmer <al******@att.netwrote:
>
Don't worry, "#pragma once" is not in the actual, real, official C99
standard, either.
It may be worth noting that one good reason that it's not there is that
it's fairly easy for the preprocessor to do that optimization itself
without any help from the user. All it has to do is note whether the
entire (non-whitespace) content of the header is protected by a macro
and, if so, make note of it so that if a later #include is seen for the
same header and the macro is defined, it can simply skip the include
processing. The GNU preprocessor has worked that way for a very long
time.

-Larry Jones

It's not denial. I'm just very selective about the reality I accept.
-- Calvin
Dec 14 '07 #17

P: n/a
Richard Heathfield wrote:
CBFalconer said:
>Martin Ambuhl wrote:
>>CBFalconer wrote:
jacob navia wrote:
Rick wrote:
>
>I'm told that "#pragma once" has made it into the ISO standard
>for either C or C++. I can't find any reference to that
>anywhere. If it's true, do any of you have a reference I can use?
>
No, it is not in the standard. Many compilers implement this
but it is not (yet) standard

Wrong. It is in the C99 standard.

Since all the C99 standard pragmas begin with
#pragma STDC
it is very difficult for
#pragma once
to be a C99 standard pragma. Would you care to share _where_ in the
standard you think this is? There are only three standard pragmas,
FP_CONTRACT, FENV_ACCESS, and CX_SELECTED_RANGE. None of them is
spelled "once".

I extracted all occurences of "#pragma" in N869 in another
article. If you really want the " once" part it is missing, but
the data is there.

Chuck, the whole context is quoted above. The question relevant to this
group is whether "#pragma once" is part of the C Standard. It is not
disputed that #pragma is part of the Standard. You claimed that Jacob
Navia was *wrong* to say that "#pragma once" is not part of the Standard,
but you have not substantiated that claim by citing the part of the
Standard in which "#pragma once" appears - and indeed you appear to
recognise that this is not possible (because it isn't actually there).

In fact, the Standard does not define "#pragma once" at all. With the three
exceptions that Martin Ambuhl pointed out, the Standard doesn't define any
#pragmas whatsoever. You have therefore incorrectly "corrected" Jacob
Navia, and therefore - by the conventions of this group which you are so
quick to attempt to enforce and yet so reluctant to observe - you owe him
an apology.
Apology delivered. Excuse: I was operating on the misconception
that the sequence was about the existence of the "#pragma" phrase
in the language (as shown by the grep instruction I used), not the
phrase "#pragma once".

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 14 '07 #18

P: n/a
la************@siemens.com wrote:
Al Balmer <al******@att.netwrote:
>Don't worry, "#pragma once" is not in the actual, real, official
C99 standard, either.

It may be worth noting that one good reason that it's not there is
that it's fairly easy for the preprocessor to do that optimization
itself without any help from the user. All it has to do is note
whether the entire (non-whitespace) content of the header is
protected by a macro and, if so, make note of it so that if a
later #include is seen for the same header and the macro is
defined, it can simply skip the include processing. The GNU
preprocessor has worked that way for a very long time.
That will usually, but not always, work, and you need to be aware
of how and why it can fail. Try the following:

/* file foo.h */
#ifndef H_foo_h
# define H_foo_h
/* foo.h content here */
# endif
/* end file foo.h */

/* file main.c */
#define H_foo_h
#include "foo.h"
/* whatever, is missing foo.h content */
int main(void) {foo(); return 0);
/* end file main.c */

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 14 '07 #19

P: n/a
ja*********@verizon.net wrote:
CBFalconer wrote:
>James Kuyper wrote:
>>CBFalconer wrote:
Rick wrote:

I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?

For example, from N869.txt:

[1] c:\stds>cat n869.txt | grep -n #pragma
9468: #pragma STDC FP_CONTRACT on-off-switch
9469: #pragma STDC FENV_ACCESS on-off-switch
9470: #pragma STDC CX_LIMITED_RANGE on-off-switch
9588: #pragma listing on "..\listing.dir"
10114: #pragma STDC CX_LIMITED_RANGE on-off-switch
11136: #pragma STDC FENV_ACCESS on-off-switch
11179: #pragma STDC FENV_ACCESS ON
11192: placed invocation of #pragma STDC FENV_ACCESS ON.165)
11208: #pragma STDC FENV_ACCESS ON pragma, and assuming the
11338: #pragma STDC FENV_ACCESS ON
11405: #pragma STDC FENV_ACCESS ON
11526: #pragma STDC FENV_ACCESS ON
12343: #pragma STDC FP_CONTRACT on-off-switch
24253: #pragma STDC CX_LIMITED_RANGE on-off-switch
24349: #pragma STDC FENV_ACCESS on-off-switch
24452: #pragma STDC FP_CONTRACT on-off-switch
25641: #pragma STDC FENV_ACCESS ON
25680: #pragma STDC FENV_ACCESS ON
25752: #pragma STDC FENV_ACCESS ON
26310: #pragma STDC FENV_ACCESS ON
26461: #pragma STDC FENV_ACCESS ON
26514: #pragma STDC FENV_ACCESS ON
26564: #pragma STDC FENV_ACCESS ON
26825: #pragma STDC FP_CONTRACT OFF
26888: #pragma STDC FP_CONTRACT OFF
27783: -- An unrecognized #pragma directive is encountered
28363: -- A non-STDC #pragma preprocessing directive that is
28367: -- A #pragma STDC preprocessing directive does not match
29051: -- The behavior on each recognized non-STDC #pragma
29522: #pragma preprocessing directive, 6.10.6

I don't see "#pragma once" anywhere in that list. If my eyes are
deceiving me, could you do something to make the location of the
word "once" more obvious?

Did you thing that grep would miss such an occurence? It didn't.

No, I think you responded to a question about "#pragma once" with an
answer about "#pragma". That was either pointless, or rude, depending
upon whether or not you were expecting us to do the follow-up "grep
once" that you should have performed. If you did expect it, you
compounded the rudeness by not explaining that fact.
No, I had the mistaken idea that everything was about the existence
of #pragma in standard C, and as a result I have wasted many
innocent electrons, peoples time, bandwidth, etc. etc. Apologies
tendered.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 14 '07 #20

P: n/a
CBFalconer <cb********@yahoo.comwrites:
la************@siemens.com wrote:
>Al Balmer <al******@att.netwrote:
>>Don't worry, "#pragma once" is not in the actual, real, official
C99 standard, either.

It may be worth noting that one good reason that it's not there is
that it's fairly easy for the preprocessor to do that optimization
itself without any help from the user. All it has to do is note
whether the entire (non-whitespace) content of the header is
protected by a macro and, if so, make note of it so that if a
later #include is seen for the same header and the macro is
defined, it can simply skip the include processing. The GNU
preprocessor has worked that way for a very long time.

That will usually, but not always, work, and you need to be aware
of how and why it can fail. Try the following:

/* file foo.h */
#ifndef H_foo_h
# define H_foo_h
/* foo.h content here */
# endif
/* end file foo.h */

/* file main.c */
#define H_foo_h
#include "foo.h"
/* whatever, is missing foo.h content */
int main(void) {foo(); return 0);
/* end file main.c */
This code will have the same effect whether the compiler includes
this optimization or not.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Dec 14 '07 #21

P: n/a
Ben Pfaff wrote:
CBFalconer <cb********@yahoo.comwrites:
>la************@siemens.com wrote:
>>Al Balmer <al******@att.netwrote:

Don't worry, "#pragma once" is not in the actual, real, official
C99 standard, either.

It may be worth noting that one good reason that it's not there is
that it's fairly easy for the preprocessor to do that optimization
itself without any help from the user. All it has to do is note
whether the entire (non-whitespace) content of the header is
protected by a macro and, if so, make note of it so that if a
later #include is seen for the same header and the macro is
defined, it can simply skip the include processing. The GNU
preprocessor has worked that way for a very long time.

That will usually, but not always, work, and you need to be aware
of how and why it can fail. Try the following:

/* file foo.h */
#ifndef H_foo_h
# define H_foo_h
/* foo.h content here */
# endif
/* end file foo.h */

/* file main.c */
#define H_foo_h
#include "foo.h"
/* whatever, is missing foo.h content */
int main(void) {foo(); return 0);
/* end file main.c */

This code will have the same effect whether the compiler includes
this optimization or not.
Yes, but if the programmer is depending on some "pragma once" to
effect the action, or on gcc magic of recognizing the control
variable, he may be hard put to understand the fault.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 15 '07 #22

P: n/a
CBFalconer <cb********@yahoo.comwrites:
James Kuyper wrote:
>CBFalconer wrote:
Rick wrote:
I'm told that "#pragma once" has made it into the ISO standard for
either C or C++. I can't find any reference to that anywhere. If
it's true, do any of you have a reference I can use?

For example, from N869.txt:

[1] c:\stds>cat n869.txt | grep -n #pragma
9468: #pragma STDC FP_CONTRACT on-off-switch
9469: #pragma STDC FENV_ACCESS on-off-switch
9470: #pragma STDC CX_LIMITED_RANGE on-off-switch
[SNIP]
29051: -- The behavior on each recognized non-STDC #pragma
29522: #pragma preprocessing directive, 6.10.6

I don't see "#pragma once" anywhere in that list. If my eyes are
deceiving me, could you do something to make the location of the
word "once" more obvious?

Did you thing that grep would miss such an occurence? It didn't.
So your point in posting that grep listing was to demonstrate that
"#pragma once" *isn't* in C99?

I, and I think everyone else who read your article, thought either
that you were trying to demonstrate that "#pragma once" *is* in C99,
or that you had misunderstood the question and were demonstrating that
"#pragma" is in C99. This was strongly reinforced by the fact that
the article to which you replied asked for a reference to "#pragma
once", and you posted an excerpt from the standard -- *without*
mentioning that the word "once" doesn't appear in the listing.
(Apparently you expected each reader to slog through the entire
listing.)

Your response was extraordinarily unclear. Simply stating your
conclusion would have made it clear.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Dec 15 '07 #23

P: n/a
CBFalconer wrote:
....
No, I had the mistaken idea that everything was about the existence
of #pragma in standard C, and as a result I have wasted many
innocent electrons, peoples time, bandwidth, etc. etc. Apologies
tendered.
Apology accepted. I thought it might be something like that.
Dec 15 '07 #24

P: n/a
Keith Thompson wrote:
>
.... snip ...
>
Your response was extraordinarily unclear. Simply stating your
conclusion would have made it clear.
I do tend to be terse. I have also had people object to my early
claims at the bridge table. :-) But there there is a clear and
immediate rule for resolution. I can't claim I will never make
that mistake again, but I will make attempts.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 15 '07 #25

P: n/a
CBFalconer wrote:
Keith Thompson wrote:
... snip ...
>Your response was extraordinarily unclear. Simply stating your
conclusion would have made it clear.

I do tend to be terse. I have also had people object to my early
claims at the bridge table. :-)

In bridge terms, I would rather call your offence here, a revoke (not
following suit), plus objecting to a valid claim... loudly. :P
--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Dec 15 '07 #26

P: n/a
Tor Rustad wrote:
CBFalconer wrote:
>Keith Thompson wrote:
... snip ...
>>Your response was extraordinarily unclear. Simply stating your
conclusion would have made it clear.

I do tend to be terse. I have also had people object to my early
claims at the bridge table. :-)

In bridge terms, I would rather call your offence here, a revoke (not
following suit), plus objecting to a valid claim... loudly. :P
I shall refrain from arguing and calling the director. :-)

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 15 '07 #27

This discussion thread is closed

Replies have been disabled for this discussion.