search

Home  >  Q&A  >  body text

“通常c++编译器并不为const创建存储空间“,可以举个例子么?

是这样么?如果真的存在,可以举个例子么?

迷茫迷茫2828 days ago796

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 15:37:49

    Usually

    const c = 10;
    a = c;

    The compiler compiles directly into

    mov [a],10

    instead of

    mov AX,[c]
    mov [a],AX

    reply
    0
  • PHPz

    PHPz2017-04-17 15:37:49

    Because const modifies a read-only variable, an initial value must be assigned when defining it. This initial value is usually a literal. The compiler will put this literal into the read-only data segment, so the variable does not need to be used during the compilation phase. Storage space, just note it in the symbol table

    reply
    0
  • Cancelreply