红联Linux门户
Linux帮助

gcc编译的bug?(已解决)

发布时间:2007-10-25 00:39:05来源:红联作者:radio
写了一段小程序,在Debian /linux 下用gcc编译成功,但是运行结果实在让人崩溃,不知道是什么原因,我找到了一个gcc的bug难道说?下面是源程序和运行结果,请大家帮忙看看怎么回事。

#include
int main( )
...{
int i,j=0;
char *id_info[]=...{"Empty","FAT 12","XENIX root","XENIX usr","FAT16( <32M)","Extended","FAT16",
"NTFS/HPFS","AIX","AIX bootable","OS/2 boot Manager","W95 FAT32","W95 FAT32(LBA)",
"","W95 FAT16 (LBA)","W95 Extended (LBA)","OPUS","Hidden FAT 12","Compaq diagnost",
"","Hidden FAT16 ( <32M)","","Hidden FAT 16","Hidden NTFS/HPFS","AST SmartSleep",
"","","Hidden W95 FAT32","Hidden W95 FAT32(LBA)","","Hidden W95 FAT16",[0x63]="Gnu Hurd",
[0x3c]="PartitionMagic",[0x52]="CP/M",[0x80]="Old Minix","Minix / Old linux",
[0x82]="Linux Swap","Linux","OS/2 Hidden","Linux extende",[0x8e]="Linux LVM",
[0xa5]="FreeBSD","OpenBSD","","","NetBSD",[0xbe]="Solaris Boot","Solaris"};
printf("Id PartitionType ");
printf("Id PartitionType ");
printf("Id PartitionType ");
printf("Id PartitionType ");
for(i=0;i if(*id_info[i] != ' ')...{
j++;
printf("0x%02x) %-20s",i,id_info[i]);
if(j%4==0) printf(" ");
}
}
printf(" ");
return 0;
}

用命令gcc -g -o list list.c编译运行以后结果如下:

Id PartitionType Id PartitionType Id PartitionType Id PartitionType
0x00) Empty 0x01) FAT 12 0x02) XENIX root 0x03) XENIX usr
0x04) FAT16( <32M) 0x05) Extended 0x06) FAT16 0x07) NTFS/HPFS
0x08) AIX 0x09) AIX bootable 0x0a) OS/2 boot Manager 0x0b) W95 FAT32
0x0c) W95 FAT32(LBA) 0x0e) W95 FAT16 (LBA) 0x0f) W95 Extended (LBA) 0x10) OPUS
0x11) Hidden FAT 12 0x12) Compaq diagnost 0x14) Hidden FAT16 ( <32M) 0x16) Hidden FAT 16
0x17) Hidden NTFS/HPFS 0x18) AST SmartSleep 0x1b) Hidden W95 FAT32 0x1c) Hidden W95 FAT32(LBA)

段错误

我都要晕了,这到底怎么回事?

//此问题已经解决,因为我的这个数组里面有很多元素是空指针,也就是指向地址0x0

//的指针,而对地址0x0的访问肯定导致段错误,因为那是系统内核的地盘。

//好了,问题解决了,在此备注一下。

解决这个问题的同时出现了另外一个问题,按照上述故障原因的分析,其实我的程序应该在输出0x1e) Hidden W95 FAT16之后才出现段错误,可是它为什么出现在了输出了0x1c) Hidden W95 FAT32(LBA)以后就出现了呢?需要进一步研究以下。
文章评论

共有 0 条评论