0
void env_create(uint8_t *binary, enum EnvType type){
    struct Env *env = NULL;
    int r = env_alloc(&env, 0); // &env = 0xf0117fcc
    cprintf("env addr: %x\n", &env); // &env = 0xf0117fbc

    if(r != 0) panic("env_create:%e", r);

    load_icode(env, binary); // &env = 0xf0117fcc
    env->env_type = type;
}

When I use gdb to inspect the address of "env", it's always 0xf0117fcc, but the correct value of "env" after calling "env_alloc" is stored at 0xf0117fbc. I wonder what may cause the problem? Thanks in advance.

1 Answers1

2

env is an auto variable. In most, if not all, C++ implementations this is implemented on the stack. You're just getting a different stack location.

user3344003
  • 20,574
  • 3
  • 26
  • 62