Is it possible to find out the variable name, the pointer pointing to?

前端 未结 3 1614
星月不相逢
星月不相逢 2020-12-20 00:58

Is it Possible to get the name of array the pointer pointing to?

example:

 char name[20];
 char *p = name
 int door_no;
 int *q = &door_no
         


        
3条回答
  •  隐瞒了意图╮
    2020-12-20 01:42

    It is not possible to get the name of the variables p or q point to if you compile and execute the program traditionally, because one of the things the compiler does is forget the name of the variables, keeping only addresses.

    Depending on what you are trying to do, you may execute the program in a non-traditional execution environment where the names are preserved. For instance,

    ~ $ cat t.c
    main(){
     char name[20];
     char *p=name;
     int door_no;
     int *q= & door_no;
    }
    ~ $ frama-c -val t.c
    [kernel] preprocessing with "gcc -C -E -I.  t.c"
    ...
    [value] ====== VALUES COMPUTED ======
    [value] Values for function main:
              p ∈ {{ &name ;}}
              q ∈ {{ &door_no ;}}
              __retres ∈ {0; }
    

提交回复
热议问题