Re: facing problem during compilation



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's
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.
But any library you use may happen to define a macro that conflicts
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"
.



Relevant Pages

  • Re: problems with ANSI C grammar for yacc
    ... >So essentialy what I need to do, is to control which namespace I am ... >5: for identifiers of variables. ... avoid using "typedef", spelling out the word "struct" instead. ... Reading email is like searching for food in the garbage, ...
    (comp.lang.c)
  • Re: Function in header file - newbie VC++/CLI
    ... #pragma once ... using namespace System; ... /// 'Resource File Name' property for the managed resource compiler tool ...
    (microsoft.public.vc.language)
  • Re: problems with ANSI C grammar for yacc
    ... > there are four name spaces of identifiers: ... > So foo in the typedef is in the fourth name space but foo in the struct ... So essentialy what I need to do, is to control which namespace I am ...
    (comp.lang.c)
  • Re: underscores in class member names
    ... I should have consulted the standard when you first said: ... This section is describing constraints on programmes. ... >> namespace identifier, i.e. its telling an implementor some details ... implementors arn't allowed to use _lowercase identifiers ...
    (comp.lang.cpp)
  • Microsoft make brain bleed
    ... using namespace System; ... #pragma region Windows Form Designer generated code ... MyClass instance; ... I want to have the event handler for button 1 execute ...
    (microsoft.public.dotnet.languages.vc)