Is this code valid C:
fputc(*("Checking 7 bytes before this string"-7), stdout);
Is there anything in the C standard against doing this? i.e reading a couple of bytes before a string literal. What about this: (assuming that these locations actually exist for the process)
for (i=(char *)0x400000; i<(char *)0x400800; ++i) fputc(*i, stdout);
If these are valid, are there any off-limit memory locations in C?
Thank you.
The first will result in undefined behavior, as you are going out of the boundaries of the string literal (underflow)
The second is example is undefined as well, as you access address that are not guaranteed to be accessible, or even exist.
The off-limit memory locations are not of C, but of the OS and the compiler.