
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 0.69 KB | hits: 13 | expires: Never
Struct pointer compatibility
typedef struct Struct1
{
short a_short;
int id;
} Struct1;
typedef struct Struct2
{
short a_short;
int id;
short another_short;
} Struct2;
typedef struct {
Struct1 struct1;
short another_short;
} Struct2;
#include <stdio.h>
typedef struct Struct1
{
short a_short;
int id;
} Struct1;
typedef struct Struct2
{
short a_short;
int id;
short another_short;
} Struct2;
int main(void)
{
Struct2 s2 = {1, 2, 3};
Struct1 *ptr = &s2;
void *vp = &s2;
Struct1 *s1ptr = (Struct1 *)vp;
printf("%d, %d n", ptr->a_short, ptr->id);
printf("%d, %d n", s1ptr->a_short, s1ptr->id);
return 0;
}