avatar
m*g
1
【 以下文字转载自 Programming 讨论区 】
【 原文由 mangmang 所发表 】
这个程序在linux/x86上用gcc编译运行没有问题;
在Solaris(UNIX)机器上编译没问题, 但一运行就bus error.
这好像是跟机器有关系, 但还没整明白. 请大侠解惑. thx.
#include
#include
void fnFoo(void *pRow);
int main()
{
char *pTableRow;
int iRowSize;
/* the row looks like: int- char10 - int - char4
*/
iRowSize = sizeof(int) * 2 + sizeof(char) * 16;
pTableRow = (char *)calloc(1, iRowSize);
fnFoo(pTableRow);
printf("->%dprintf("->%s
avatar
x*g
2
As I remember, solaris is more strict on alignment.
So an int has to be int aligned. If you cast a char* to an int*,
you might get bus error.
Try change your pTableRow to an int* and cast to char* whenever needed.

【在 m******g 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 【 原文由 mangmang 所发表 】
: 这个程序在linux/x86上用gcc编译运行没有问题;
: 在Solaris(UNIX)机器上编译没问题, 但一运行就bus error.
: 这好像是跟机器有关系, 但还没整明白. 请大侠解惑. thx.
: #include
: #include
: void fnFoo(void *pRow);
: int main()
: {

avatar
m*g
3
thx a lot !

【在 x******g 的大作中提到】
: As I remember, solaris is more strict on alignment.
: So an int has to be int aligned. If you cast a char* to an int*,
: you might get bus error.
: Try change your pTableRow to an int* and cast to char* whenever needed.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。