lundi 26 janvier 2015

Initializing a pointer in struct in at minimum lines


I'm currently new to C programming, and appreciate for any tip.


Is there a shorter way to initialize struct pointers in C without removing the pointer tags? Thanks~



typedef struct {
int x, y, z;
} Point3;

typedef struct {
Point3 *pos, *direction;
} Vector;

int main() {
Vector *p;
p = malloc(sizeof(Vector));
p->pos = malloc(sizeof(Point3));
p->direction = malloc(sizeof(Point3));
return 0;
}




Aucun commentaire:

Enregistrer un commentaire