Topic: underscore-prepended variable names(http://www.newscene.com/)
Author: Pete Becker <petebecker@acm.org>
Date: 1999/11/28 Raw View
Al Stevens wrote:
>
> >No. That's the point: include guards for standard headers should begin
> >with an underscore followed by an uppercase letter, or with two
> >underscores. Those names are reserved to the implementor. Any user code
> >that contains identifiers like that is illegal.
> >
> >#define __STD_CSTDIO_H
> >#include <cstdio>
>
> You misunderstand. The discussion isn't about how it is but how it might
> have been. "Of all sad words of tongue and pen, the saddest are these..." Or
> something like that.
>
Yup, I finally figured that out. Of course, if we insisted on perfect
designs we'd spend all of our time designing and never finish any
products.
--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.com
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/11/26 Raw View
Al Stevens wrote:
>
> >If this code appears in system header files, it's dangerous because
> >users can define macros with this name:
> >
> >#define STD_CSTDIO_H
> >#include <cstdio>
>
> As they can any other symbol the implementation chooses, rule or no rule (as
> things are now).
Yes, and code which breaks the rules is allowed to have undefined
behavior, so such code is not a problem. That's the very reason why
breaking those rules has been specified as allowing undefined behavior.
Only code that obeys the rules is relevant for evaluating the
conformance of an implementation. An implentation that #defines
STD_CSTDIO_H can cause problems even for code which obeys the rules, and
that would make such an implementation non-conforming.
Conforming implementations currently avoid such problems when #defining
macros in standard headers, by using names from the name space reserved
to the implementation for all uses. A conforming implementation can do
this, since legal user code does not use identifiers with such names.
You've suggested, with regard to implementations #defining macros with
such names: "Perhaps that usage should not be permitted." If it's not to
be permitted, how could a conforming implementation implement include
guards for standard headers without breaking legal user code?
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Pete Becker <petebecker@acm.org>
Date: 1999/11/26 Raw View
Al Stevens wrote:
>
> >If this code appears in system header files, it's dangerous because
> >users can define macros with this name:
> >
> >#define STD_CSTDIO_H
> >#include <cstdio>
>
> As they can any other symbol the implementation chooses, rule or no rule (as
> things are now).
>
No. That's the point: include guards for standard headers should begin
with an underscore followed by an uppercase letter, or with two
underscores. Those names are reserved to the implementor. Any user code
that contains identifiers like that is illegal.
#define __STD_CSTDIO_H
#include <cstdio>
If this doens't work, it's the user's fault for using an identifier
that's reserved to the implementor. Granted, the compiler can't detect
this, but in practice this is not a problem. Just don't do it.
--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Al Stevens" <alstevens@midifitz.com>
Date: 1999/11/27 Raw View
>You've suggested, with regard to implementations #defining macros with
>such names: "Perhaps that usage should not be permitted." If it's not to
>be permitted, how could a conforming implementation implement include
>guards for standard headers without breaking legal user code?
I answered that question in another message.
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Al Stevens" <alstevens@midifitz.com>
Date: 1999/11/27 Raw View
>No. That's the point: include guards for standard headers should begin
>with an underscore followed by an uppercase letter, or with two
>underscores. Those names are reserved to the implementor. Any user code
>that contains identifiers like that is illegal.
>
>#define __STD_CSTDIO_H
>#include <cstdio>
You misunderstand. The discussion isn't about how it is but how it might
have been. "Of all sad words of tongue and pen, the saddest are these..." Or
something like that.
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]