Thread: question about naming variables/functions

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    221

    question about naming variables/functions

    what does it mean if u begin a variable/function name with __ (an underscore or 2)?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It means you've started it with two underscores...


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    It also means you're breaking, or close to breaking, a C standard ruling. Read about them here .

    Personally, I avoid naming variables that begin with an underscore.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >It also means you're breaking, or close to breaking, a C standard ruling.
    Or to be more precise, you're most definitely using an identifier that is reserved in all cases by the implementation:
    7.1.3 Reserved identifiers
    ...
    -- All identifiers that begin with an underscore and either an uppercase letter or another
    underscore are always reserved for any use.
    >Personally, I avoid naming variables that begin with an underscore.
    A good habit to get into. Much easier than remembering the complex rules concerning reserved identifiers.
    My best code is written with the delete key.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>you're most definitely using an identifier that is reserved in all cases by the implementation<<
    Well... nit picking the nit picker.... a name like _myvar isn't reserved according to that rule But let's not get too deep.

    Welcome back, btw.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Well... nit picking the nit picker.... a name like _myvar isn't reserved according to that rule
    That's true, the next rule that I didn't paste explains how the single underscore works:
    — 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.


    >Welcome back, btw.
    Thanks.
    My best code is written with the delete key.

  7. #7
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    I thought it meant you were Microsoft. It's used as a warning to users.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM