girish writes:
> Another quick newbie question:
>
> The program segfaults because there is a memory violation of some sort - is
> it because the program is trying to write to some memory area marked
> read-only?
>
> > char *ptr = "adam";
> Where is ptr getting stored and where does it get stored when I use
> -xstrconst?
'ptr' itself is allocated in the .data segment. However, the literal
string "adam" is stored in .rodata.
You actually have two objects there -- a pointer, which is itself
mutable, and a constant string, which might or might not be, depending
on compiler options.
That's quite different from (for example):
char ptr[] = "adam";
(To be fair at this, the compiler _should_ have given a warning or
error for your code, because you're initializing a 'char *' pointer
from a 'const char *' pointer. Discarding 'const' without an explicit
cast is a programming error.)
> Can anyone give me some tips on how I can find this out from the
> compiled binary file?
elfdump might be helpful.
--
James Carlson, Solaris Networking <[EMAIL PROTECTED]>
Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code