|
Home > Archive > Unix Programming > February 2005 > Newbie Question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I would like to know what are the underscores for in .h files for example:
#ifdef __cplusplus
#ifndef __THROW
#ifndef __need_getopt
and so on ...
thank you ,Luke
| |
| SM Ryan 2005-02-20, 6:19 pm |
| lkoszanski@gmail.com (Luke) wrote:
# I would like to know what are the underscores for in .h files for example:
#
# #ifdef __cplusplus
# #ifndef __THROW
# #ifndef __need_getopt
Double underscores are supposed to indicate things that are private
to the vendor's include file: you get to see them because C/C++ can't hide
them, but you're not supposed to see them. Unless whoever made the include
file wants to explain them, you should pay no attention to the man behind
the curtain.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
She broke your heart and inadvertendently drove men to deviant lifestyles.
| |
| Måns Rullgård 2005-02-20, 6:19 pm |
| SM Ryan <wyrmwif@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
> lkoszanski@gmail.com (Luke) wrote:
> # I would like to know what are the underscores for in .h files for example:
> #
> # #ifdef __cplusplus
> # #ifndef __THROW
> # #ifndef __need_getopt
>
> Double underscores are supposed to indicate things that are private
> to the vendor's include file: you get to see them because C/C++ can't hide
> them, but you're not supposed to see them. Unless whoever made the include
> file wants to explain them, you should pay no attention to the man behind
> the curtain.
__cplusplus is special here. It is automatically defined by C++
compilers, but not by C compilers, mainly so header files can say
#ifdef __cplusplus
extern "C" {
#endif
--
Måns Rullgård
mru@inprovide.com
| |
| Floyd L. Davidson 2005-02-20, 6:19 pm |
| Måns Rullgård <mru@inprovide.com> wrote:
>SM Ryan <wyrmwif@tango-sierra-oscar-foxtrot-tango.fake.org> writes:
>
>
>__cplusplus is special here. It is automatically defined by C++
>compilers, but not by C compilers, mainly so header files can say
>
>#ifdef __cplusplus
>extern "C" {
>#endif
Hmmm... that doesn't make it very special! It's just like every
other identifier that begins with a underscore plus either an
upper case alpha or another underscore. Here's what the C99
Standard says,
7.1 Library
...
7.1.3 Reserved identifiers
1 Each header declares or defines all identifiers listed in
its associated subclause, and optionally declares or defines
identifiers listed in its associated future library
directions subclause and identifiers which are always
reserved either for any use or for use as file scope
identifiers.
- All identifiers that begin with an underscore and either
an uppercase letter or another underscore are always
reserved for any use.
- All identifiers that begin with an underscore are always
reserved for use as identifiers with file scope in both
the ordinary and tag name spaces.
- Each macro name in any of the following subclauses
(including the future library directions) is reserved
for use as specified if any of its associated headers is
included; unless explicitly stated otherwise (see 7.1.4).
...
--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@barrow.com
| |
| Måns Rullgård 2005-02-20, 6:19 pm |
| floyd@barrow.com (Floyd L. Davidson) writes:
> Måns Rullgård <mru@inprovide.com> wrote:
>
> Hmmm... that doesn't make it very special! It's just like every
> other identifier that begins with a underscore plus either an
> upper case alpha or another underscore.
Perfectly true. By special, I was referring to the reply that they
should be ignored. Things like __need_getopt have no meaning outside
the header files using them, and should be ignored by application
programmers. __cplusplus has a well-defined meaning, and can be
reliably assumed to be defined whenever a C++ compiler is being used.
--
Måns Rullgård
mru@inprovide.com
| |
| Brian Raiter 2005-02-20, 6:19 pm |
| > I would like to know what are the underscores for in .h files for example:
>
> #ifdef __cplusplus
> #ifndef __THROW
> #ifndef __need_getopt
>
> and so on ...
They aren't separate from the symbols -- C sees the underscore
character as a perfectly acceptable character to use in identifiers.
Identifiers that start with underscores and/or double-underscores are
reserved for particular purposes, but this is merely a convention
(though mandated by the standards), not a syntactial feature of the
language proper.
b
|
|
|
|
|