- 论坛徽章:
- 0
|
本帖最后由 teaco77 于 2011-08-13 11:44 编辑
请教一个问题,用arm-linux-gcc4.3.2编译,在arm的开发板上运行时,前一个结构体调用时总是出现Segmentation fault,改成后一个,uint16改为uint32就好了,请问这是什么问题?怎样避免这个错误 ?
typedef struct
{
uint16 ms_line ;
uint16 ms_vole ;
uint16 now_line ;
uint16 now_vole ;
uint16 hz_style ;
uint16 asc_style ;
uint16 show_style ;
uint32 buf_size ;
uint32 fstyle ;
uint8 *ptrshow ;
}show_buf;
//改为下面这种后,不报Segmentation fault运行错误
typedef struct {
uint32 ms_line ;
uint32 ms_vole ;
uint32 now_line ;
uint32 now_vole ;
uint32 hz_style ;
uint32 asc_style ;
uint32 dis_style ;
uint32 buf_size ;
uint32 fstyle ;
uint8 *ptrshow ;
}show_buf ;
程序如下:
show_buf *mainshow_ptr ;
show_buf * dshow_init(uint16 lin , uint16 vol, uint32 mod)
{
mainshow_ptr=(show_buf *)malloc(sizeof(show_buf));
memset(mainshow_ptr,0x00,sizeof(show_buf));
printf("mainshow size is: %#x\n",sizeof(show_buf));
mainshow_ptr->ms_line =lin;
mainshow_ptr->ms_vole =vol; //这句出错 改成mainshow_ptr->ms_vole =0; 时可以运行不报Segmentation fault出错
mainshow_ptr->now_line=lin ;
mainshow_ptr->now_vole =vol;
mainshow_ptr->hz_style=0 ;
mainshow_ptr->asc_style=0 ;
mainshow_ptr->show_style=mod ;
mainshow_ptr->buf_size=3200 ;
mainshow_ptr->fstyle=0 ;
mainshow_ptr->ptrshow=(uint8 *) malloc (3200);
memset(mainshow_ptr->ptrshow,0x00,3200);
return mainshow_ptr;
}
调用:
mainshow_ptr = dsshow_init(160,160,4) ; |
|