| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | string constants |
Hi andrew
ac> Hi there. Why does emx/gcc disallow the modification of string constants?
ac> Or more to the point - why does ANSI/ISO C disallow this? Tnx.
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.
Hmm.. if the standard says so, shouldn't the compiler have been
able to detect the problem by implicitly declaring str as constant
or something equivalent?
ac> When compiled
ac> with Borland C++ for DOS 3.1, Microsoft QuickC 2.5 or Borland C++ for OS/2
ac> 1.0, the following code executes without error. CLint 1.41 also passed the
ac> following code with flying colors.
ac> #include
ac> int main(void)
ac> {
ac> char *str = "Hello world";
ac> *(str + 5) = '\0';
ac> printf("str: `%s'\n", str);
ac> return 0;
ac> }
Very interesting. Emphasises the difference between program space
and data space, I spose, cos the "Hello world" in the above code
lives in the program, not the data. But shouldn't the same rule
apply to
int i = 1;
?
Cheers
--- PPoint 1.88
* Origin: Silicon Heaven (3:711/934.16)SEEN-BY: 711/809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.