免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2417 | 回复: 0
打印 上一主题 下一主题

请教一个linux下C语言结构体的问题? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-08-13 09:36 |只看该作者 |倒序浏览
本帖最后由 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) ;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP