Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Mar 2001 16:26:13 +0300
From:      Vladimir Mandro <vlaman@smela.ldc.net>
To:        freebsd-bugs@freebsd.org
Subject:   bug in gcc or my hands?
Message-ID:  <E14jLOP-0000yy-00@vlaman.smela.ldc.net>

next in thread | raw e-mail | index | archive | help
Hello!

I discovered some strange gcc actions.

Compiling program:

---begin of main.c---
void main()
{
char *s = "Hello";
*s=0;
}
---end of main.c---

gcc -o exp1 main.c

Executing:

myhost@myhost$ ./exp1
Bus error (core dumped)

Running gdb. Stepping through program. All works fine and program
finishes succesfully. Running gdb again. Running program without
breakpoints or stepping. Line *s=0 causes segmentation fault.

OK.

Replacing char *s = "Hello" with char s[] = "Hello". All works fine.

Book "The C Programming Language" by Kernighan&Ritchie tells, that
declaration char *s and char s[] are equivalent.

Whats wrong?

Thanks.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E14jLOP-0000yy-00>