g++ segmentation fault

Florian Lohoff flo at rfc822.org
Wed Apr 26 16:13:49 CEST 2000


On Wed, Apr 26, 2000 at 04:15:18PM +0200, Dietmar Guhe wrote:
> Mist, keine Punkte in dieser Runde.
> 
> Abgetippt aus C The Complete Reference (Seite 128):
>  
> char *p ="hello world";
> 
> As you can see, the pointer p is not an array. the reason this sort of
> initialization works is because of the way the compiler operates. All C
> compilers create what is called a string table, which is used internally
> by the compiler to store the string constants used by the program.
> Therfore, the preceding declaration statement places the addres of "hello
> world", as stored in the string table, into the pointer p. Throughout a
> program, p can be used like any other string. ...
> 
> Aber eben leider nicht, als ein Speicherbereich, der "frei" verfuegbar
> ist. 
> So verstehe ich das zumindest.

Ist ja richtig - Aber da das als const abgelegt wird (Eine assumption die
der gcc macht) und der wie man aus der manpage entnehmen kann
meherere vorkommen von "text" zusammenoptimiert (Mehrfach genutztes "text" wird
zu einem vorkommen) muss der das natuerlich write protecten um
zu verhindern das ein fragment des codes "text" durch "test" ersetzt und
dann das naechste frament sich wieder auf die constante verlaesst.

Ich denke mal das man das in der ANSI C spezifikation wiederfinden kann.

Flo
-- 
Florian Lohoff		flo at rfc822.org		      	+49-subject-2-change
"Technology is a constant battle between manufacturers producing bigger and
more idiot-proof systems and nature producing bigger and better idiots."


-
Hinweise zur Benutzung dieser (und anderer Mailing-Listen) bitte beachten:
--> http://lug-owl.de/mailinglist_hints.html <--



More information about the Linux mailing list