What takes up more space: a structure or switch statement, with the same amount of members? I am assuming the space used is determined by the compiler; mine is gcc.
thanks!
thanks!
typedef struct s_nameTypes
{
int id;
char *name;
} NameTypes;
int apples = 0x1;
int oranges = 0x2;
NameTypes names[] =
{
{ apples, "i am an apple" },
{ oranges, "i am an orange" },
{ 0x0, "i don't know what i am" }
}
while( names[i] != 0x0 )
if( someID == names[i].id )
strcpy(myname, names[i].name);
int apples = 0x1;
int oranges = 0x2;
switch( someID )
{
case oranges :
strcpy( myname, "I am an apple!");
break;
case apples :
strcpy( myname, "I am an orange!");
break;
}
Comment