Thread: Reserved namespace and illegal names

  1. #1
    FOX
    Join Date
    May 2005
    Posts
    188

    Reserved namespace and illegal names

    I've googled intensively, and I just can't any comprehensive online resource for a list of illegal names and other naming conventions that are in the in the reserved namespace.

    While you're at it, you might as well include a similar resource for C++ if you have it handy.

    And oh, is there a compile switch to GCC that makes it complain when you intrude on the reserved namespace? I couldn't find anything in the man pages.

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    [C mode]whats a namespace?[/C mode]

  3. #3
    FOX
    Join Date
    May 2005
    Posts
    188
    Quote Originally Posted by sand_man
    [C mode]whats a namespace?[/C mode]
    For example, everything starting with str or mem followed by a lowercase letter, is reserved according to the C standard. Or everything with the suffix _t and so on.

  4. #4
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    I'm pretty sure they aren't illegal, and I doubt they're actually reserved. If I'm wrong, I'd like somebody to shove a quote in my face proving my ignorance and complete ineptness of programming.

    I think using those naming conventions yourself would be sort of handy, as if you're extending those groups of functions (assuming they actually perform string or memory related tasks). The only thing I've consciously stayed away from was the double under score for the beginning of variable names.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    _t is reserved by POSIX not ANSI C.

    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 anyuse 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 anyuse.
    —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 anyof the following subclauses (including the future library directions) is reserved for use as specified if anyofits associated headers is included; unless explicitly stated otherwise (see 7.1.4).
    —All identifiers with external linkage in anyofthe following subclauses (including the future library directions) are always reserved for use as identifiers with external linkage. 142)
    —Each identifier with file scope listed in anyofthe following subclauses (including the future library directions) is reserved for use as macro and as an identifier with file scope in the same name space if anyofits associated headers is included.

    2 No other identifiers are reserved. If the program declares or defines an identifier in a context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved identifier as a macro name, the behavior is undefined.

    3 If the program removes(with#undef)any macro definition of an identifier in the first group listed above,the behavior is undefined.
    Sorry for the terrible paste, that's Preview.app for you.
    Last edited by orbitz; 08-11-2005 at 06:46 PM.

  6. #6
    FOX
    Join Date
    May 2005
    Posts
    188
    Oh well, I knew the suffix _t was reserved by some important standard.

    But I'm sure that str*, mem* and wcs* are reserved according to the C standard.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    Are you so sure? What I pasted is the entire reserved identifier section of teh C99 spec and i don't ese anything about str* mem* or wcs* there. I think it's another POSIX issue.

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    C89 Draft: 4.13 FUTURE LIBRARY DIRECTIONS

    The following names are grouped under individual headers for convenience. All external names described below are reserved no matter what headers are included by the program.

    4.13.1 Errors <errno.h>
    Macros that begin with E and a digit or E and an upper-case letter (followed by any combination of digits, letters and underscore) may be added to the declarations in the <errno.h> header.

    4.13.2 Character handling <ctype.h>
    Function names that begin with either is or to , and a lower-case letter (followed by any combination of digits, letters and underscore) may be added to the declarations in the <ctype.h> header.

    4.13.3 Localization <locale.h>
    Macros that begin with LC_ and an upper-case letter (followed by any combination of digits, letters and underscore) may be added to the definitions in the <locale.h> header.

    4.13.4 Mathematics <math.h>
    The names of all existing functions declared in the <math.h> header, suffixed with f or l , are reserved respectively for corresponding functions with float and long double arguments and return values.

    4.13.5 Signal handling <signal.h>
    Macros that begin with either SIG and an upper-case letter or SIG_ and an upper-case letter (followed by any combination of digits, letters and underscore) may be added to the definitions in the <signal.h> header.

    4.13.6 Input/output <stdio.h>
    Lower-case letters may be added to the conversion specifiers in fprintf and fscanf . Other characters may be used in extensions.

    4.13.7 General utilities <stdlib.h>
    Function names that begin with str and a lower-case letter (followed by any combination of digits, letters and underscore) may be added to the declarations in the <stdlib.h> header.

    4.13.8 String handling <string.h>
    Function names that begin with str , mem , or wcs and a lower-case letter (followed by any combination of digits, letters and underscore) may be added to the declarations in the <string.h> header.
    ~~~~

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    http://web.archive.org/web/200402090...h/c-predef.htm

    [edit]
    Quote Originally Posted by sand_man
    [C mode]whats a namespace?[/C mode]
    By the way, C has had name spaces for quite some time.
    Last edited by Dave_Sinkula; 08-11-2005 at 10:11 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. % illegal error?
    By alyeska in forum C++ Programming
    Replies: 7
    Last Post: 09-09-2008, 08:07 AM
  2. illegal else without matching if HELP!!!!
    By vodka9er in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2007, 04:09 PM
  3. Illegal use of IOS error
    By Xanth in forum C++ Programming
    Replies: 7
    Last Post: 02-26-2005, 02:26 PM
  4. Help finding solution to illegal operator
    By nickadeemus2002 in forum C++ Programming
    Replies: 1
    Last Post: 07-11-2004, 10:32 PM
  5. illegal pure syntax
    By kippwinger in forum C++ Programming
    Replies: 8
    Last Post: 10-06-2003, 01:45 AM