C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

#pragma STDC ONCE: interest?
Goto page 1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Gennaro Prota
Guest





PostPosted: Wed Dec 06, 2006 12:39 am    Post subject: #pragma STDC ONCE: interest? Reply with quote



Hi,

given that there will be much rewording and expansion in clause 16 of
the standard to bring it in synch with C99 I was thinking to submit a
proposal for a "pragma once" directive, in the form

#pragma STDC ONCE

I'd like to know, however, if committee members here feel that the
proposal will have a concrete chance to be considered.

--
Gennaro Prota. C++ developer. For hire.
(to mail me, remove any 'u' from the address)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Pete Becker
Guest





PostPosted: Wed Dec 06, 2006 12:39 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote



Gennaro Prota wrote:
Quote:

given that there will be much rewording and expansion in clause 16 of
the standard to bring it in synch with C99

Those changes have already been made. See
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1653.htm.

Quote:
I was thinking to submit a
proposal for a "pragma once" directive, in the form

#pragma STDC ONCE

I'd like to know, however, if committee members here feel that the
proposal will have a concrete chance to be considered.


I'm under the impression that everyone who has implemented this has come
to the conclusion that it's not worth the bother. But aside from
technical merits, the deadline for new submissions for C++0x has passed,
so I doubt that a new proposal would get much consideration.

For an overview of the status of the various extension proposals for
C++0x see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2122.htm.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Gennaro Prota
Guest





PostPosted: Wed Dec 06, 2006 12:39 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote



On Tue, 5 Dec 2006 15:05:30 CST, Pete Becker wrote:

Quote:
I'm under the impression that everyone who has implemented this has come
to the conclusion that it's not worth the bother. But aside from
technical merits, the deadline for new submissions for C++0x has passed,
so I doubt that a new proposal would get much consideration.

The advantage is for the user, as it relieves from inventing a name
for the include guard macro. Also it is so simple to specify and
implement... Perhaps for C++1x, then.

--
Gennaro Prota. C++ developer. For hire.
(to mail me, remove any 'u' from the address)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
peter koch
Guest





PostPosted: Wed Dec 06, 2006 4:52 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

Gennaro Prota skrev:
Quote:
Hi,

given that there will be much rewording and expansion in clause 16 of
the standard to bring it in synch with C99 I was thinking to submit a
proposal for a "pragma once" directive, in the form

#pragma STDC ONCE

I'd like to know, however, if committee members here feel that the
proposal will have a concrete chance to be considered.

--
Gennaro Prota. C++ developer. For hire.
(to mail me, remove any 'u' from the address)

I don't really see the purpose of that pragma in the first place, but

as you are doubtlessly more knowledgeable than me in this area, lets
ignore that and assume that pragma once is useful.
In that case, why not simply use the de facto standard format - #pragma
once. Looks nicer that way, I think.

/Peter

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Pete Becker
Guest





PostPosted: Wed Dec 06, 2006 4:59 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

Gennaro Prota wrote:
Quote:

The advantage is for the user, as it relieves from inventing a name
for the include guard macro. Also it is so simple to specify and
implement... Perhaps for C++1x, then.


It is not simple to specify, nor is it simple to implement (if it were,
the simplistic analysis on Wikipedia wouldn't have a list of compilers
that got it wrong). Remember, an included file can be out on a network
somewhere, on an unknown file system, accessible through multiple paths,
with different names.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Gennaro Prota
Guest





PostPosted: Wed Dec 06, 2006 6:22 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

On Tue, 5 Dec 2006 22:59:35 GMT, Pete Becker wrote:

Quote:
Gennaro Prota wrote:

The advantage is for the user, as it relieves from inventing a name
for the include guard macro. Also it is so simple to specify and
implement... Perhaps for C++1x, then.


It is not simple to specify, nor is it simple to implement (if it were,
the simplistic analysis on Wikipedia wouldn't have a list of compilers
that got it wrong).

Hmm, could you please provide a link? I can't find any article with
such a list.

Quote:
Remember, an included file can be out on a network
somewhere, on an unknown file system, accessible through multiple paths,
with different names.

I know. But the EDG front-end, and gcc, claim to recognize the include
guard idiom. How can they implement it correctly?

--
Gennaro Prota. C++ developer. For hire.
(to mail me, remove any 'u' from the address)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Seungbeom Kim
Guest





PostPosted: Wed Dec 06, 2006 6:46 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

Gennaro Prota wrote:
Quote:
On Tue, 5 Dec 2006 15:05:30 CST, Pete Becker wrote:

I'm under the impression that everyone who has implemented this has come
to the conclusion that it's not worth the bother. But aside from
technical merits, the deadline for new submissions for C++0x has passed,
so I doubt that a new proposal would get much consideration.

The advantage is for the user, as it relieves from inventing a name
for the include guard macro. Also it is so simple to specify and
implement... Perhaps for C++1x, then.

Even if it were admitted into C++0x or C++1x, you would still have to
write the include guards yourself anyway in any serious program to
support old compilers, wouldn't you? And you couldn't argue otherwise
because supporting old compilers is trivially easy (3 more lines).

Then I don't see much benefit in such a change. Maybe it's way easier
just to write a program that generates the include guards.

$ genhdr headername.h
$ cat headername.h
#ifndef HEADERNAME_H_INCLUDED
#define HEADERNAME_H_INCLUDED

#endif
$ _

Or there probably are ones already. It's just that writing one myself or
even searching for a good one costs more than writing out the include
guard when I need it. :)

--
Seungbeom Kim

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Nevin :-] Liber
Guest





PostPosted: Wed Dec 06, 2006 6:46 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

In article <5d2cn2tvg6te1r2h5otocpmsec5e9gl2sk (AT) 4ax (DOT) com>,
geunnaro_prouta (AT) yahoo (DOT) com (Gennaro Prota) wrote:

Quote:
I know. But the EDG front-end, and gcc, claim to recognize the include
guard idiom. How can they implement it correctly?

The include guard idiom is based on macro symbols, not on whether or not
two files are the same file. Information about the latter must be
provided by the operating system.

--
Nevin "Smile" Liber <mailto:nevin (AT) eviloverlord (DOT) com>

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
James Kanze
Guest





PostPosted: Wed Dec 06, 2006 4:07 pm    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

Seungbeom Kim wrote:
Quote:
Gennaro Prota wrote:
On Tue, 5 Dec 2006 15:05:30 CST, Pete Becker wrote:

I'm under the impression that everyone who has implemented this has come
to the conclusion that it's not worth the bother. But aside from
technical merits, the deadline for new submissions for C++0x has passed,
so I doubt that a new proposal would get much consideration.

The advantage is for the user, as it relieves from inventing a name
for the include guard macro. Also it is so simple to specify and
implement... Perhaps for C++1x, then.

Even if it were admitted into C++0x or C++1x, you would still have to
write the include guards yourself anyway in any serious program to
support old compilers, wouldn't you? And you couldn't argue otherwise
because supporting old compilers is trivially easy (3 more lines).

Then I don't see much benefit in such a change. Maybe it's way easier
just to write a program that generates the include guards.

$ genhdr headername.h
$ cat headername.h
#ifndef HEADERNAME_H_INCLUDED
#define HEADERNAME_H_INCLUDED

#endif
$ _

Or there probably are ones already. It's just that writing one myself or
even searching for a good one costs more than writing out the include
guard when I need it. Smile

Does anyone use an editor which doesn't do this (and insert
other boilerplate text as well) whenever you open a file which
doesn't exist and whose name ends in .h, .hh, .hpp, etc.? It
seems like a standard feature, present in all of the editors I
use (vim, emacs) except the original vi. Of course, you have to
configure it to do so, but I would expect this to be the case in
any normal development environment---you also want boilerplate
copyright notices, and who knows what all else. (I've found it
useful to put

// Local Variables: --- for emacs
// mode: c++ --- for emacs
// tab-width: 8 --- for emacs
// End: --- for emacs
// vim: set ts=8 sw=4 filetype=cpp: --- for vim

at the end of all of my sources, for example. And you should
see what gets generated if the filename ends with .html:-).)

If you don't know how to do this with your current editor, ask
in the appropriate forum for that editor. You'll typically find
a package already available which does most of the work. (I
forget what I used with emacs, but I know that I didn't have to
write a single line of elisp:-).)

Of course, in a lot of cases, your source code management system
will take care of these details, so you don't have to bother
configuring the editor.

--
James Kanze (GABI Software) email:james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
James Kanze
Guest





PostPosted: Wed Dec 06, 2006 5:45 pm    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

Nevin :-] Liber wrote:
Quote:
In article <5d2cn2tvg6te1r2h5otocpmsec5e9gl2sk (AT) 4ax (DOT) com>,
geunnaro_prouta (AT) yahoo (DOT) com (Gennaro Prota) wrote:

I know. But the EDG front-end, and gcc, claim to recognize the include
guard idiom. How can they implement it correctly?

The include guard idiom is based on macro symbols, not on whether or not
two files are the same file. Information about the latter must be
provided by the operating system.

The optimization based on recognizing it is based on recognizing
that two includes actually include the same file. And the
reason that it can be implemented correctly is that it isn't an
error if they do happen to read the same file twice; it just
results in a slower compile time. So they can take a
conservative strategy, and in case of doubt, skip the
optimization. This would not be the case in the case of #pragma
once.

--
James Kanze (GABI Software) email:james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Peter Steiner
Guest





PostPosted: Wed Dec 06, 2006 5:46 pm    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

Seungbeom Kim wrote:
Quote:

Then I don't see much benefit in such a change. Maybe it's way easier
just to write a program that generates the include guards.

besides the improvement in usability, a pragma once statements
decreases preprocessor runtime cost. include guards don't allow the
preprocessor to omit the file for obvious reasons, while pragma once
does so.

this can result in a significant preprocessor speed up.

-- peter

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
peter koch
Guest





PostPosted: Wed Dec 06, 2006 11:23 pm    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

Gennaro Prota skrev:
Quote:
On Tue, 5 Dec 2006 22:52:31 CST, peter koch wrote:

[ #pragma STDC ONCE ]

I'd like to know, however, if committee members here feel that the
[snip]
why not simply use the de facto standard format - #pragma
once. Looks nicer that way, I think.

I now understand that the "STDC" form of the pragma is for

"standardised" pragmas and would thus support that form as well.
Quote:
My favourite form would actually be:

#once

There's no need, I think, to bring "pragma" into it. As I said, the
usefulness of the construct lies in the fact that it doesn't require
any user-defined identifier. (In retrospect, I guess the include once
behavior should have been the default, with a directive to request
otherwise, but that's (perhaps) too late to change, especially now
that many "recursive inclusion" techniques have been popularized by
the boost preprocessor library)

The names of my controlling macros usually encode the project name,
the filename, the developer's name and the date of creation of the
file, and are automatically generated, but still that's not enough to
avoid any reasonable conflict.

My controlling macro once had a tail of "blind typing" so it looked
somewhat like
#if !defined
INCLUDE_HPPlsfvugasovytgsurkxjtlouejrasvnyhjsytdjcyvlistcge
#define INCLUDE_HPPlsfvugasovytgsurkxjtlouejrasvnyhjsytdjcyvlistcge

much to the amusement of my fellow collegues. I fell victim for their
teasing and now follow your way (including also the time of day). I
doubt the likelyhood of having identical guards is more than
hypothetical.
One more serious consideration is what to do with linked files. Is it
always possible to determine that a headerfile has already been drawn
in when the name is different? I would not bet on that and would thus
prefer the good old guards.

Kind regards
Peter

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Gennaro Prota
Guest





PostPosted: Wed Dec 06, 2006 11:42 pm    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

On Tue, 5 Dec 2006 22:52:31 CST, peter koch wrote:

Quote:
[ #pragma STDC ONCE ]

I'd like to know, however, if committee members here feel that the
proposal will have a concrete chance to be considered.

I don't really see the purpose of that pragma in the first place, but
as you are doubtlessly more knowledgeable than me in this area,

Not at all :-)

Quote:
lets ignore that and assume that pragma once is useful.
In that case, why not simply use the de facto standard format - #pragma
once. Looks nicer that way, I think.

My favourite form would actually be:

#once

There's no need, I think, to bring "pragma" into it. As I said, the
usefulness of the construct lies in the fact that it doesn't require
any user-defined identifier. (In retrospect, I guess the include once
behavior should have been the default, with a directive to request
otherwise, but that's (perhaps) too late to change, especially now
that many "recursive inclusion" techniques have been popularized by
the boost preprocessor library)

The names of my controlling macros usually encode the project name,
the filename, the developer's name and the date of creation of the
file, and are automatically generated, but still that's not enough to
avoid any reasonable conflict.

--
Gennaro Prota. C++ developer. For hire.
(to mail me, remove any 'u' from the address)

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Ben Hutchings
Guest





PostPosted: Thu Dec 07, 2006 5:23 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

On 2006-12-06, Peter Steiner <pnsteiner (AT) gmail (DOT) com> wrote:
Quote:
Seungbeom Kim wrote:

Then I don't see much benefit in such a change. Maybe it's way easier
just to write a program that generates the include guards.

besides the improvement in usability, a pragma once statements
decreases preprocessor runtime cost. include guards don't allow the
preprocessor to omit the file for obvious reasons, while pragma once
does so.
snip


#pragma once has been suggested many times, but it's difficult to
specify and may be impossible to implement on some common systems.
I know a popular compiler that implements #pragma once which allows a
file containing #pragma once that's on a case-insensitive file-system
to be included more than once if the include directives use differing
capitalisation,

Another popular compiler recognises the #ifndef FOO...#define FOO...
#endif pattern and avoids repeatedly reading such files (so long as it
recognises them) if the controlling macro is still defined. Even if
it fails to recognise two paths as pointing to the same file, this only
makes compilation a little slower.

I know which behaviour I prefer.

Ben.

--
Ben Hutchings
Never attribute to conspiracy what can adequately be explained by stupidity.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
eric_backus@alum.mit.edu
Guest





PostPosted: Thu Dec 07, 2006 7:21 am    Post subject: Re: #pragma STDC ONCE: interest? Reply with quote

peter koch wrote:
Quote:
One more serious consideration is what to do with linked files. Is it
always possible to determine that a headerfile has already been drawn
in when the name is different? I would not bet on that and would thus
prefer the good old guards.

Which failure is more likely:

* Your system supports linked files, the include files in your project
make use of that, but the compiler can't figure out that two files are
linked together, or
* You use good old include guards, but accidentally use the same
include guard in different include files, due to using cut-and-paste to
create one of the files.

I'm pretty sure the second is much more likely--I've seen it happen.
To me, the issue is not that include guards are trivially easy for
people to use (they are), the issue is that people occasionally make
mistakes and duplicate the include guards, and that include guards by
definition pollute the global namespace.

I understand the difficulties in determining file identity when you
involve networking, hard and soft links, and so on. But I would think
the standard could just say that file identity is determined in an
implementation defined way, and leave this as a quality of
implementation issue.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Goto page 1, 2, 3, 4, 5, 6, 7  Next
Page 1 of 7

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.