Naming conventions and name mangling

In C++, any name that starts with and underscore followed by an uppercase letter and any name that contains two consecutive underscores is reserved for any use [lib.global.names] and any name that begins with an underscore is reserved in the global namespace. The intent for this, as explained by several people on comp.std.c++ is to allow C++ name mangling to result in valid names in C (because the two underscores restriction does not exist in C).

A naming convention I have been using for a few years now includes a rule about scope: anything with member scope has one underscore at the end; anything with global scope (including static class members and enumerators) have two. Technically, this breaks the requirement of [lib.global.names]. I have yet to find a standards-compliant compiler, however, that is not able to handle this correctly. If you know of one, let me know.

About rlc

Software Analyst in embedded systems and C++, C and VHDL developer, I specialize in security, communications protocols and time synchronization, and am interested in concurrency, generic meta-programming and functional programming and their practical applications. I take a pragmatic approach to project management, focusing on the management of risk and scope. I have over two decades of experience as a software professional and a background in science.
This entry was posted in C & C++ and tagged . Bookmark the permalink.

One Response to Naming conventions and name mangling

  1. Paercebal says:

    Shame on you.
    🙂

    More seriously, I know some people (whose skills I do respect anyway) who will prefix any private method with an underscore. I believe this to be a C habit…

    Now, I feel a lot less ashamed by my “Javascript Hungarian Notation”…
    🙂

Comments are closed.