Does giving data an effective type count as a side-effect?

前端 未结 2 2074
半阙折子戏
半阙折子戏 2021-02-06 07:31

Suppose I have a chunk of dynamically allocated data:

void* allocate (size_t n)
{
  void* foo = malloc(n);
  ...
  return foo;
}

I wish to use

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 07:46

    The phrase from the standard that you are citing clearly only states something about the access to the object. The only changes to the effective type of the object that the standard describes are the two phrases before that, that clearly describe that you have to store into the object with the type that you want to make effective.

    6.5/6

    If a value is stored into an object having no declared type through an lvalue having a type that is not a character type, then the type of the lvalue becomes the effective type of the object for that access and for subsequent accesses that do not modify the stored value.

提交回复
热议问题