J
jigsaw
I found that a simple c program is treadted diffrently with bcc32 and
gcc.
The bcc++ version is: Borland C++ 5.5.1 for Win32 Copyright (c) 1993,
2000 Borland, under WinXP Pro
The gcc version is: gcc 4.0.2, under ubuntu 5.1
The c program is:
/* code start */
#include <stdio.h>
int
main(void)
{
char *s;
s = "abc";
s[0] = 'b'; /* s is expected to be "bbc" now */
printf("%s\n", s);
return 0;
}
/* code end */
This program can pass compilation under both bcc32 and gcc.
And it runs as I had expected under WinXP - the output is "bbc".
But when I tried to run it under ubuntu, it fails with one line of
message: Segmentation fault
I also use splint to examin the program, splint compains that:
/* splint start */
Splint 3.1.1 --- 28 Apr 2003
test.c: (in function main)
test.c:8:2: Suspect modification of observer s[0]: s[0] = 'b'
Storage declared with observer is possibly modified. Observer storage
may not
be modified. (Use -modobserver to inhibit warning)
test.c:7:6: Storage s[0] becomes observer
Finished checking --- 1 code warning
/* splint end*/
But I just don't understand what splint is trying to express.
Can anyone do me a favor to point out the flaw of my program? thx
gcc.
The bcc++ version is: Borland C++ 5.5.1 for Win32 Copyright (c) 1993,
2000 Borland, under WinXP Pro
The gcc version is: gcc 4.0.2, under ubuntu 5.1
The c program is:
/* code start */
#include <stdio.h>
int
main(void)
{
char *s;
s = "abc";
s[0] = 'b'; /* s is expected to be "bbc" now */
printf("%s\n", s);
return 0;
}
/* code end */
This program can pass compilation under both bcc32 and gcc.
And it runs as I had expected under WinXP - the output is "bbc".
But when I tried to run it under ubuntu, it fails with one line of
message: Segmentation fault
I also use splint to examin the program, splint compains that:
/* splint start */
Splint 3.1.1 --- 28 Apr 2003
test.c: (in function main)
test.c:8:2: Suspect modification of observer s[0]: s[0] = 'b'
Storage declared with observer is possibly modified. Observer storage
may not
be modified. (Use -modobserver to inhibit warning)
test.c:7:6: Storage s[0] becomes observer
Finished checking --- 1 code warning
/* splint end*/
But I just don't understand what splint is trying to express.
Can anyone do me a favor to point out the flaw of my program? thx