With a 32-bit OS, we know that the pointer size is 4 bytes, so sizeof(char*) is 4 and sizeof(int*) is 4, etc. We also know that when you increment a char*, the byte address (offset) changes by sizeof(char); when you increment an int*, the byte address changes by sizeof(int).
My question is:
- How does the OS know how much to increment the byte address for
sizeof(YourType)?
The compiler only knows how to increment a pointer of type
YourType *if it knows the size ofYourType, which is the case if and only if the complete definition ofYourTypeis known to the compiler at this point.For example, if we have:
Then you are allowed to do this:
but you are not allowed to do this:
..since
struct YourTypeis a complete type, butstruct YourOtherTypeis an incomplete type.The error given by
gccfor the lineb++;is: