g++ segmentation fault

Florian Lohoff flo at rfc822.org
Wed Apr 26 11:30:22 CEST 2000


On Wed, Apr 26, 2000 at 11:29:47AM +0200, Thomas Balls-Thies wrote:
> Hallo,
> 
> ich weiß nicht, ob es sich bei meinem Problem wirklich um ein Linux-
> bzw. Gnu-Problem handelt, hoffe aber, daß Ihr mir trotzdem helfen könnt.
> 
> Ich versuche gerade, C++ zu erlernen. Wenn ich in einem Programm eine
> Zeile wie
> 
>    a[0] = 'n'; 
> 
> habe (a ist als String deklariert), wird dies ohne Murren von g++
> compiliert, stürzt beim ausführen aber mit "segmentation fault" ab (bei
> Unix entsprechend mit "Bus error(coredump)"). Kommentiere ich die Zeile
> aus, läuft das Programm durch. Ich habe auf eine falsche Verwendung der
> 'Hochkommata' getippt und schon  verschiedenen Versionen ausprobiert,
> aber die obige ist die einzige, bei der der Compiler nicht meckert.
> 
> Kann jemand mit meiner spärlichen Fehlerbeschreibung etwas anfangen?

Jein - Ich mache kein C++ - Aber - C ...

(flo at ping)/tmp# cat j.c

void main(void ) {
        char    *a;
        a[0]='n';
}

(flo at ping)/tmp# gcc -O0 -g -o j j.c
(flo at ping)/tmp# gdb j
GNU gdb 4.17.m68k.objc.threads.hwwp.fpu.gnat
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-pc-linux-gnu"...
(gdb) r
Starting program: /tmp/j 

Program received signal SIGSEGV, Segmentation fault.
0x8048469 in main () at j.c:4
4               a[0]='n';
(gdb) q
(flo at ping)/tmp# vi j.c
(flo at ping)/tmp# cat j.c 

void main(void ) {
        char    a[255];
        a[0]='n';
}
(flo at ping)/tmp# ./j
(flo at ping)/tmp# 


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