Я получил ошибку сегментации, когда вызвал функцию сразу после назначения указателя.
typedef struct
{
DMINT field1;
DMINT field2;
DMINT field3;
} MSG1;
typedef struct
{
....
} MSG;
/* MSG is size of 1040 byte, bigger than MSG1 in size */
int main()
{
MSG Msg;
MSG1 *pMsg1;
int mid;
pthread_t tid;
...
Recv_msg( mid, &Msg); /* this function does a memcpy to &Msg */
pMsg1 = (MSG1 *)&Msg;
//ret = pthread_join(pMsg1->..... ); /* Got Segmentation fault here by GDB*/
/* even the first argument has nothing to do with pMsg1, SEGV is still received */
ret = pthread_creat(&tid, NULL, thread_function, NULL); /* Got Segmentation fault here by GDB*/
Работает нормально, если удалить pMsg1 = (MSG1 *)&Msg
.Это потому, что два указателя имеют разные размеры?