Sunday, October 17, 2010

sizeof, structures, and fread

I just read about structure padding, and now I'm worried.

If I have a file stream going and I want to shuttle in some data to a structure with fread(), will it go "too far" into the stream if I do this?

fread(&stuff, sizeof(struct putstuffhere), 1, filepointer);

What if my structure is an int and a char... it's technically five bytes, but sizeof will return eight! Will my file pointer location go three bytes too far into the stream if I try to read data into that five byte structure?

I can't find any info on this.

No comments:

Post a Comment