C ++ pointer names

I understand that pointers are used to point to objects, so in a program you have to be the same. But there were also how the names of the pointers are stored. It would be redundant to declare a pointer name that takes up more resources than the object it points to, for example:

int intOne = 0;
int *this_pointer_is_pointing_towards_intOne = &intOne;

I know this is a ridiculous example, but I was just trying to understand this idea.

Edit: The name of the pointer should be stored somewhere, occupying more bytes than the address of the object indicated on the object.

+5
source share
8 answers

The length of the variable name does not affect the size of your program, but simply the time it takes to write the program.

+22
source

, , . . , (, , -). .

, , , , . , , .

, . (. strip, ).

, -. . :

readelf -sW /usr/lib/libboost_*-mt.so  | awk '{ print length($0), $0 }' | sort -n
+14

. ( ) ( ).

- ( ), , , , , .

+9

Microsoft "p" :

int intOne = 0;
int* pIntOne = &intOne;

Hungarian .

, . , .

, , , - , , .:)

+4

, - . , , . . :

void myfunc(const char *var) {
    // Function body
}

char 4 32- , char - 1 . ( var , , .) ? , ( ) :

void myfunc(const string &str) {
    // Function body
}

, , const.

+2

, - . / .

+1

, / .

ptr, . .

0

, :

  • , C/++, .
    • N.B. , , ,
    • , , , , , !
  • , , , , , , . , , COM, , ( ), , , , :
    /*
        pszString could be pointing to only one character which
        is less space than the pointer
    */
    HRESULT OneLetterSplat(char * pszString)
    {
        *pszString = 'a';
        return SUCCESS
    }
    
0
source

All Articles