Thread: Variable names starting with _

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    146

    Variable names starting with _

    Hi,

    In many codes and projects, I find variable names, structure definition, headerfile names starting with _ (underscore sign). Is that supposed to mean anything? Are they treated in some different manner?

    Edesign

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I believe names with a '_' preceeding them are reserved for compiler/implementation specific names.

    That means, unless you're building a compiler or something, you're technically not supposed to do that.

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Variable names can start with an underscore. There's no problem with that. Heres a simple example.
    Code:
    #include<stdio.h>
    int main(void)
    {
    	int _it;
    	scanf("%d",&_it);
    	printf("%d",_it);
    }
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by BEN10 View Post
    Variable names can start with an underscore.
    In some cases. But it is not always true.

    Compilers are known to accept incorrect coding constructs.

    The C standard Section 7.1.3 "Reserved identifiers" has this to say on the subject.
    Each header declares or defines all identifiers listed in its associated subclause, and optionally declares or defines identifiers listed in its associated future library directions subclause and identifiers which are always reserved either for any use or for use as file scope identifiers.
    — All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
    — 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.
    (other categories of reserved identifiers not related to this topic not quoted).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. variable names in Waterloo BASIC
    By Thantos in forum Tech Board
    Replies: 4
    Last Post: 12-27-2007, 04:57 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. underscore and variable names
    By l2u in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 09:57 AM
  4. Use of variable
    By alice in forum C Programming
    Replies: 8
    Last Post: 06-05-2004, 07:32 AM
  5. Variable Names based on Variable Values
    By mrpickle in forum C++ Programming
    Replies: 6
    Last Post: 01-27-2003, 10:33 AM