structs with unions

SGDK only sub forum

Moderator: Stef

Post Reply
matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

structs with unions

Post by matteus » Wed Sep 07, 2016 7:27 pm

Does the SGDK support unions? I can't get this code to work!!

Code: Select all

struct Script {
    char type;
    union {
        struct {
            char charName[24];
            char charDialogue[480];
        } CharacterDialogue;
        struct {
            char menuItem1[24];
            char menuItem2[24];
            char menuItem3[24];
            char menuItem4[24];
            char menuItem5[24];
            char menuItem6[24];
        } Menu;
    };
};
enum {
    TypeCharacterDialogue,
    TypeMenu
};

struct Script array[10];
array[0].type = TypeCharacterDialogue;
array[0].CharacterDialogue.charName = 'Dave';
array[0].CharacterDialogue.charDialogue = 'Why will this not work?!?#';
array[1].type = TypeMenu;
array[1].Menu.menuItem1 = = 'Its rubbish';
array[1].Menu.menuItem2 = 'Its crap',
array[1].Menu.menuItem3 = 'Its a pain',
array[1].Menu.menuItem4 = 'Its something',
array[1].Menu.menuItem5 = 'Its meh',
array[1].Menu.menuItem6 = 'Its pants';

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: structs with unions

Post by matteus » Wed Sep 07, 2016 8:23 pm

answered my own problem as per usual :D (okay not as usual) lol

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: structs with unions

Post by Stef » Wed Sep 07, 2016 10:23 pm

SGDK uses GCC so yeah of course it supports union as it's part of C language :)

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: structs with unions

Post by Miquel » Thu Sep 08, 2016 10:20 pm

You even can use unnamed unions if you don't like that much verbose. Is my opinion that unions are the best memory manager there is for genny.
HELP. Spanish TVs are brain washing people to be hostile to me.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: structs with unions

Post by matteus » Mon Sep 12, 2016 5:42 pm

Thanks! I might give that a go!

Post Reply