Re: facing problem during compilation
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 21 Sep 2007 16:22:05 -0700
jacob navia <jacob@xxxxxxxxxxxxxxxx> writes:
Richard Tobin wrote:
In article <lnejgrdfoy.fsf@xxxxxxxxxxxxxxx>,
Keith Thompson <kst-u@xxxxxxx> wrote:
Using this pattern presents a risk of stepping on the implementation'sBut any library you use may happen to define a macro that conflicts
reserved namespace if your header name happens to start with 'e',
since identifiers starting with an upper-case 'E' followed by another
upper-case letter are reserved as errno macros.
with a name you choose. The chance of an implementation defining an
errno ending _H is no greater - and probably much smaller, because it
would be Obviously Stupid.
-- Richard
The problem has no solution
besides...
#pragma once
But we have discussed this several times. I think
#pragma once
is a good solution and my compiler system implements it.
With this pragma, there is NO NEED to figure out a name.
But of course your code loses portability to implementations that
don't support #pragma once. I wouldn't mind if it had been
standardized, but it wasn't. (And determining whether two names refer
to the same file can be non-trivial on some systems; the #ifndef
technique lets the programmer assign a unique name to each file.)
In any case, C has a fundamental problem with name collisions. The
usual workaround is to apply a common prefix to each visible
identifier, but there's no real guarantee that two organizations won't
pick the same prefix. Even C++-style namespaces and other similar
mechanisms don't completely solve the problem, unless you can set up
and enforce a central registry of prefixes, or namespace names, or
whatever.
#pragma once is a nice feature, and it's useful for reasons other than
avoiding name collisions, but it only addresses one small piece of the
general name collision problem.
In practice, programmers *usually* can manage to pick unique names
with only occasional problems. There are no perfect solutions, but
there are plenty of imperfect ones.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: facing problem during compilation
- From: jacob navia
- Re: facing problem during compilation
- References:
- facing problem during compilation
- From: junky_fellow@xxxxxxxxxxx
- Re: facing problem during compilation
- From: Martien verbruggen
- Re: facing problem during compilation
- From: Keith Thompson
- Re: facing problem during compilation
- From: Richard Tobin
- Re: facing problem during compilation
- From: jacob navia
- facing problem during compilation
- Prev by Date: Re: Logical XOR
- Next by Date: Boolean data type?
- Previous by thread: Re: facing problem during compilation
- Next by thread: Re: facing problem during compilation
- Index(es):
Relevant Pages
|