How many people do you think have really read what compilers generate? I haven't seen people who often used do while because he doesn't need an additional jmp on the cycle condition.
Yeah, I recently switched to macos, C without CRT and other things that are in windows are easier to read, sometimes I look at how Clang optimizes the code if there are controversial points, it does not always optimize correct)))
char: 1 bytes (with some exceptions)
int: at least two bytes, usually 4.
double*: the compiler may be 64 bit and the OS may be 64 bit but maybe it is generating 32 bit code or there may be extra security info stored in the pointer so it may be 16 bytes.
char*: same.
24 makes sense if there are three bytes of padding with the char, so the int after it is aligned to 4 bytes.
So it's 1 bytes for the char, 3 bytes of padding, 4 bytes of int, and 8 bytes of pointer and another 8 bytes of pointer. So 24 in total assuming one normal, commonly used environment.
Even if it is a byte buffer, if you want to read the int just like that it needs to be aligned, since the unaligned access is UB.
Sure you can read it as bytes by memcpy'ing it into an aligned int (also might avoid strict aliasing shenanigans) but there are always trade-offs to be made.
That would be a wrong assumption which directly violates the requirements of the question. The question was “what is the minimum length of a byte buffer that can store this data”, not “estimate how many bytes this data would take up in some scenario of your choice”.
This is why programming, of any kind, has psychological implications. People always scoff at such a notion, as it is counter to the vision of everything digital in nature being frictionless, but no medium should grant people freedom from the consequences of their actions. How else will we learn?🤔😇
Comments
int: at least two bytes, usually 4.
double*: the compiler may be 64 bit and the OS may be 64 bit but maybe it is generating 32 bit code or there may be extra security info stored in the pointer so it may be 16 bytes.
char*: same.
The correct answer: I don't know
So it's 1 bytes for the char, 3 bytes of padding, 4 bytes of int, and 8 bytes of pointer and another 8 bytes of pointer. So 24 in total assuming one normal, commonly used environment.
Sure you can read it as bytes by memcpy'ing it into an aligned int (also might avoid strict aliasing shenanigans) but there are always trade-offs to be made.
The question was simply “what is the minimum length of a byte buffer that can store this data”, and it got the answer wrong.