Dereferencing type-punned pointer will break strict-aliasing rules-Collection of common programming errors

It looks a lot as if you really want to use fread:

int data;
fread(&data, sizeof(data), 1, stream);

That said, if you do want to go the route of reading chars, then reinterpreting them as an int, the safe way to do it is to use a union:

union
{
    char theChars[4];
    int theInt;
} myunion;

for(int i=0; i

Originally posted 2013-11-09 23:07:36.