Dereferencing type-punned pointer will break strict-aliasing rules

后端 未结 7 1473
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 01:05

I used the following piece of code to read data from files as part of a larger program.

double data_read(FILE *stream,int code) {
        char data[8];
              


        
7条回答
  •  悲哀的现实
    2020-12-01 01:09

    Using a union is not the correct thing to do here. Reading from an unwritten member of the union is undefined - i.e. the compiler is free to perform optimisations that will break your code (like optimising away the write).

提交回复
热议问题