reason for _funname() and funname()

This is a discussion on reason for _funname() and funname() within the C++ Programming forums, part of the General Programming Boards category; Hi I have seen this before but I am confused as to why people do so. If there is a ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    23

    reason for _funname() and funname()

    Hi I have seen this before but I am confused as to why people do so. If there is a technical term to better define it please do let me know

    If you look at the code below

    Code:
    Code:
    class _Correl
    {
    public:
        double Nom;
        double DeNom1, DeNom2;
    
        _Correl( double val ) { Nom = DeNom1 = DeNom2 = val; }
        void operator=( double val ) { Nom = DeNom1 = DeNom2 = val; }
        operator double() { return Nom / sqrt( DeNom1 * DeNom2 ); }
    };
    
    class Correl
    {
    public:
        typedef _Correl result_type;
    
        Correl() { mean1 = mean2 = 0; }
        Correl( double _mean1, double _mean2 = 0 ) { mean1 = _mean1; mean2 = _mean2; }
    
        template<class Val> result_type operator () ( result_type s, Val val1, Val val2 )
            {
                double v1 = val1 - mean1;
                double v2 = val2 - mean2;
                s.Nom += v1 * v2;
                s.DeNom1 += v1 * v1;
                s.DeNom2 += v2 * v2;
                return s;
            }
    protected:
        double mean1;
        double mean2;
    };
    there are terms like "class Correl" and "typdef _Correl"

    "mean1 = _mean1" "double _mean1"

    Now I do understand that mean1 and _mean1 are different
    but why do codders (at higher level) use "_name of (variable/function etc.).

    I have seen this in header files of VC++ as well?

    If there is some documentation that I could refer on this matter I would like to know.

    Thanks
    Nipun

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    From C99 (not the C++ standard, but you can be pretty sure something similar appears)
    7.1.3 Reserved identifiers

    [#1] 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.
    > I have seen this in header files of VC++ as well?
    Which is the only place you should see them, and where they are allowed to be.
    Defining any symbol with a leading underscore, or using such-like from a system header file is non-standard usage.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21