Thread: Underscore prefix

  1. #1
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Posts
    64

    Question Underscore prefix

    Hi,
    I have seen a lot that some function arguments use as prefix the "underscore" character. For example:
    Code:
    void* malloc(size_t _Size);
    It is a common way to declare the function arguments this way or it is reserved only to the standard functions (e.g. from "<stdio.h>")?

    Thanks.
    Petike

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not at all common, and in fact, that type of identifier is reserved for the compiler implementation.

    It is not a bad idea to mark arguments differently from local variables, but using underscore at the beginning of symbols is not a good plan at all.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Posts
    64
    Thanks.
    Petike

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by matsp
    It is not a bad idea to mark arguments differently from local variables
    That is debatable since arguments (or (formal) parameters, if you prefer) are local variables. Petike, considering that your example was of a standard library function, you probably really are looking at an implementation of the standard library, hence the use of a name reserved to the implementation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    That is debatable since arguments (or (formal) parameters, if you prefer) are local variables.
    Yes they are. But I can just say that our coding standards where I work, we mark member variables, arguments to functions and local variables differently (and global modifiable variables are near enough forbidden...). One reason pointers (and references in C++) ithat are arguments will potentially modify data outside of the function. Local variables (unless they point to data passed in by reference or pointer) are not changing anything outside of the function. I'm not sure if there are other reasons (I wasn't there several years ago when they got the coding standards set up).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    http://web.archive.org/web/200402090...def.htm#Groups
    (I lose track of that page too frequently.)
    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. longest prefix
    By Marksman in forum C Programming
    Replies: 1
    Last Post: 03-14-2009, 11:19 PM
  2. underscore use in c++
    By te5la in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2008, 03:24 PM
  3. Atomic Operations
    By Elysia in forum Windows Programming
    Replies: 27
    Last Post: 03-27-2008, 02:38 AM
  4. which to prefix with std:: ??
    By wakish in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2005, 02:58 PM
  5. Prefix Expressions
    By mannyginda2g in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2004, 01:30 AM