• Create Account

### #Actualultramailman

Posted 25 March 2013 - 10:50 PM

Hello.
I've figured out the format of object UID's in my 2d game.

It will be like this:
struct uid{
int16_t n; //the nth object of a chunk of world
int8_t cell_x; //coordinate of the chunk the object belongs to
int8_t cell_y;
};

It would be nice if I can use it as a number:
union obj_uid{
int32_t id;
struct uid parts;
};

However, if I remember correctly, that is undefined behaviour (write to one field and read from another).

Is there a portable way to treat "struct uid" as one integer, or should I just use "struct uid" as the sole type for uid?

### #1ultramailman

Posted 25 March 2013 - 10:48 PM

Hello.
I've figure out how the format of object UID's in my 2d game.

It will be like this:
struct uid{
int16_t n; //the nth object of a chunk of world
int8_t cell_x; //coordinate of the chunk the object belongs to
int8_t cell_y;
};

It would be nice if I can use it as a number:
union obj_uid{
int32_t id;
struct uid parts;
};

However, if I remember correctly, that is undefined behaviour (write to one field and read from another).

Is there a portable way to treat "struct uid" as one integer, or should I just use "struct uid" as the sole type for uid?

PARTNERS