Are macro names subject to the double/leading underscore restrictions?

Discussion in 'C++' started by Pete C, Dec 14, 2006.

  1. Pete C

    Pete C Guest

    I was looking at Section 17.4.3.1 and I can't work out whether macro
    names are also covered by Section 17.4.3.1.2 ("Global names").

    I often see preple chastised for using include guards like
    _INCLUDED_BLAH_H (and I avoid them myself "just to be on the safe
    side"). But if this is a mistake, then it is an astonishingly common
    one. There are dozens of well-known libraries in my /usr/include that
    do it.

    Is this technically a mistake that doesn't matter in practice, or does
    Section 17.4.3.1.2 refer only to post-processed names?

    Thanks,
    Pete
    Pete C, Dec 14, 2006
    #1
    1. Advertising

  2. Pete C

    red floyd Guest

    Pete C wrote:
    > I was looking at Section 17.4.3.1 and I can't work out whether macro
    > names are also covered by Section 17.4.3.1.2 ("Global names").
    >
    > I often see preple chastised for using include guards like
    > _INCLUDED_BLAH_H (and I avoid them myself "just to be on the safe
    > side"). But if this is a mistake, then it is an astonishingly common
    > one. There are dozens of well-known libraries in my /usr/include that
    > do it.
    >
    > Is this technically a mistake that doesn't matter in practice, or does
    > Section 17.4.3.1.2 refer only to post-processed names?
    >
    > Thanks,
    > Pete
    >


    *ANY* identifier with a leading underscore followed by an uppercase, or
    two consecutive underscores is subject to 17.4.3.1.2. Period.
    red floyd, Dec 14, 2006
    #2
    1. Advertising

  3. Pete C

    red floyd Guest

    Pete C wrote:
    > I was looking at Section 17.4.3.1 and I can't work out whether macro
    > names are also covered by Section 17.4.3.1.2 ("Global names").
    >
    > I often see preple chastised for using include guards like
    > _INCLUDED_BLAH_H (and I avoid them myself "just to be on the safe
    > side"). But if this is a mistake, then it is an astonishingly common
    > one. There are dozens of well-known libraries in my /usr/include that
    > do it.
    >

    /usr/include *is* your implementation. Since the identifiers in
    question are reserved to the implementation, /usr/include is quite free
    to use them.
    red floyd, Dec 14, 2006
    #3
  4. Pete C

    Pete C Guest

    red floyd wrote:
    > /usr/include *is* your implementation. Since the identifiers in
    > question are reserved to the implementation, /usr/include is quite free
    > to use them.


    Hmm... I'm pretty sure that when the standard says "the
    implementation", it isn't referring to wxWidgets, boost, gtkmm or any
    other crufty old library I happen to have installed in /usr/include ...
    surely it is just referring to the implementation of ISO/IEC 14882 ?
    Pete C, Dec 14, 2006
    #4
  5. Pete C

    Pete Becker Guest

    Pete C wrote:
    > red floyd wrote:
    >> /usr/include *is* your implementation. Since the identifiers in
    >> question are reserved to the implementation, /usr/include is quite free
    >> to use them.

    >
    > Hmm... I'm pretty sure that when the standard says "the
    > implementation", it isn't referring to wxWidgets, boost, gtkmm or any
    > other crufty old library I happen to have installed in /usr/include ...
    > surely it is just referring to the implementation of ISO/IEC 14882 ?
    >


    That's right. Being in /usr/include is not a license to use reserved
    names. That's reserved to the compiler and its associated headers.

    --

    -- Pete
    Roundhouse Consulting, Ltd. (www.versatilecoding.com)
    Author of "The Standard C++ Library Extensions: a Tutorial and
    Reference." (www.petebecker.com/tr1book)
    Pete Becker, Dec 14, 2006
    #5
  6. Pete C wrote:

    > I often see preple chastised for using include guards like
    > _INCLUDED_BLAH_H (and I avoid them myself "just to be on the safe
    > side"). But if this is a mistake, then it is an astonishingly common
    > one. There are dozens of well-known libraries in my /usr/include that
    > do it.


    There are thousands of people, books, magazine articles, help files, web
    pages and usenet posts that uses void main, and is still incorrect
    according to the standard.

    There are millions of programs with bugs, but that fact will not must
    encourage anything to write buggy code on purpose.

    --
    Salu2
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Dec 14, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Walter Tross

    leading underscore for member names

    Walter Tross, Apr 29, 2004, in forum: C++
    Replies:
    5
    Views:
    535
    Sumit Rajan
    Apr 29, 2004
  2. Sydex
    Replies:
    12
    Views:
    6,451
    Victor Bazarov
    Feb 17, 2005
  3. Axter

    leading underscore

    Axter, Nov 11, 2005, in forum: C++
    Replies:
    10
    Views:
    552
  4. Steven D'Aprano

    Double underscore names

    Steven D'Aprano, Feb 12, 2008, in forum: Python
    Replies:
    5
    Views:
    611
    Steven D'Aprano
    Feb 13, 2008
  5. Ulrich Eckhardt

    With or without leading underscore...

    Ulrich Eckhardt, Aug 10, 2009, in forum: Python
    Replies:
    4
    Views:
    317
    Bruno Desthuilliers
    Aug 11, 2009
Loading...

Share This Page