C++ programmers! How do you use unnamed 'namespace's ?

Discussion in 'C++' started by Razmig K, Sep 4, 2003.

  1. Razmig K

    Razmig K Guest

    Dear mates,
    This is a small survey for C++ programmers to speak their mind about
    the uses and/or potential advantages and disadvantages resulting from
    the use of the aforementioned C++ feature in ralistic code in various
    programming domains.
    Thank you.

    //rk
     
    Razmig K, Sep 4, 2003
    #1
    1. Advertising

  2. Hi Razmig,

    "Razmig K" <> wrote in message
    news:...
    | This is a small survey for C++ programmers to speak their mind about
    | the uses and/or potential advantages and disadvantages resulting from
    | the use of the aforementioned C++ feature in ralistic code in various
    | programming domains.

    I *always* use an anonymous namespace around small utility classes
    (e.g. predicates and functors for STL algorithm calls) defined in
    an implementation (.cpp) file. This is the easiest and the only safe
    way to avoid name clashes in C++.

    For isolated internal functions and global variables (if ever...),
    I may still use 'static' instead of an anonymous namespace.
    In spite of it being deprecated -- old habits die hard...
    (and using 'static' helps portability to older & C compilers).

    Realistic code: absolutely
    Programming domain: from embedded/RT SW to Mloc OO/GUI applications.


    Cheers,
    Ivan

    --
    http://www.post1.com/~ivec <> Ivan Vecerina
     
    Ivan Vecerina, Sep 4, 2003
    #2
    1. Advertising

  3. Razmig K

    jeffc Guest

    "Razmig K" <> wrote in message
    news:...
    > Dear mates,
    > This is a small survey for C++ programmers to speak their mind about
    > the uses and/or potential advantages and disadvantages resulting from
    > the use of the aforementioned C++ feature in ralistic code in various
    > programming domains.


    They are useful either in large programs or when using third party libraries
    (where you're using someone else's code, but can't change it) to avoid name
    clashes.
     
    jeffc, Sep 4, 2003
    #3
  4. Razmig K wrote:

    > This is a small survey for C++ programmers to speak their mind about
    > the uses and/or potential advantages and disadvantages resulting from
    > the use of the aforementioned C++ feature in ralistic code in various
    > programming domains.


    I use it when I want to introduce filescope. For instance, I'm using an
    algorithm like for_each(), and I want to have functor to pass to it, then I
    put the functor in the anonymous namespace in the .cpp file. Kinda a
    replacement for static.

    --
    John L. Fjellstad

    A: Top posting!
    Q: What is the most irritating thing on Usenet?
     
    John L Fjellstad, Sep 5, 2003
    #4
    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. Doris Cox
    Replies:
    0
    Views:
    545
    Doris Cox
    Dec 2, 2003
  2. Dennis
    Replies:
    0
    Views:
    693
    Dennis
    Dec 2, 2003
  3. Dennis
    Replies:
    0
    Views:
    448
    Dennis
    Dec 2, 2003
  4. marco_segurini
    Replies:
    4
    Views:
    1,009
    Rob Williscroft
    Jun 16, 2004
  5. marco_segurini

    unnamed namespace and friend

    marco_segurini, Feb 3, 2005, in forum: C++
    Replies:
    1
    Views:
    356
    msalters
    Feb 3, 2005
Loading...

Share This Page