* String literals
@ 2000-04-05 12:53 zeljko oluic
2000-04-05 17:04 ` Martin v. Loewis
0 siblings, 1 reply; 2+ messages in thread
From: zeljko oluic @ 2000-04-05 12:53 UTC (permalink / raw)
To: gcc-help
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1491 bytes --]
Hi dear fellow,
Â
I am having a problem running the enclosed test program. I expected
program to pass the test points 1, 2 and 3 but instead it cored at point
2 (3). After looking into generated assembler code I noticed that
string literals casted to array initializers (see pointers S2
and s3) were put into read only segment. Is this correct (i.e. in compilance
with ANSI C standard ) ?
I am running gcc version 2.95.2 19991024 on SCO UNIX.
Â
Â
Thanks for your help,
Â
Zeljko Oluic
Â
Enc. strings test program
Â
#include <stdio.h>
Â
Â
char S1[] = "can be modified";
char *S2 = (char []) {"can be modified too"};
Â
Â
void
string_constant(void)
{
   char *s1;
   char *s2;
   char *s3;
Â
Â
   s1 = "if modified possible run-time error";
   s2 = "if modified possible run-time error";
   s3 = (char []) {"can be modified too"};
Â
Â
   if (s1 == s2) printf("shared strings\n");
   else printf("strings are not shared\n");
Â
   printf("the following need to be ok\n");
   printf("1\n");
   S1[0] = 'x';
   printf("2\n");
   S2[0] = 'x';
   printf("3\n");
   s3[0] = 'x';
Â
   printf("the following can cause a run-time error\n");
   s1[0] = 'x';
Â
   if (*s1 == 'x') printf("strings are writable\n");
   else printf("strings are not writable\n");
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: String literals
2000-04-05 12:53 String literals zeljko oluic
@ 2000-04-05 17:04 ` Martin v. Loewis
0 siblings, 0 replies; 2+ messages in thread
From: Martin v. Loewis @ 2000-04-05 17:04 UTC (permalink / raw)
To: zoluic; +Cc: gcc-help
> I am having a problem running the enclosed test program. I expected
> program to pass the test points 1, 2 and 3 but instead it cored at
> point 2 (3). After looking into generated assembler code I noticed
> that string literals casted to array initializers (see pointers S2
> and s3) were put into read only segment. Is this correct (i.e. in
> compilance with ANSI C standard ) ?
Yes, this is indeed in compliance with the ISO C standard. gcc has an
option -fwritable-strings if you really need that function.
Regards,
Martin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-04-05 17:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-05 12:53 String literals zeljko oluic
2000-04-05 17:04 ` Martin v. Loewis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).