ac> Note that the following code when compiled with emx/gcc will cause an
ac> exception error when executed, due to this ANSI/ISO C rule.
RM> Hmm.. if the standard says so, shouldn't the compiler have been
RM> able to detect the problem by implicitly declaring str as constant
RM> or something equivalent?
I guess what you want is something like "const char *str",
presumably they allow normal assignment for compatibility
with the trillions of lines of code already in existance.
ac> int main(void)
ac> {
ac> char *str = "Hello world";
ac> *(str + 5) = '\0';
ac> printf("str: `%s'\n", str);
ac> return 0;
ac> }
RM> Very interesting. Emphasises the difference between program space
RM> and data space, I spose, cos the "Hello world" in the above code
RM> lives in the program, not the data. But shouldn't the same rule
RM> apply to
RM> int i = 1;
That's a very good example. Modifying the literal "Hello world"
is the equivalent of modifying the "1" in "i = 1". Since the
compiler would probably generated "MOV EAX, 1" or somesuch for
the latter, I'd like to see you try and modify the "1" to
something else. BFN. Paul.
@EOT:
---
* Origin: X (3:711/934.9)
|