Ok, say I have the following:
and I want a string to have a type as an array of char, so how can I do so?Code:typedef enum {Void,Integer,Boolean,Char, Null} Type;
Ok, say I have the following:
and I want a string to have a type as an array of char, so how can I do so?Code:typedef enum {Void,Integer,Boolean,Char, Null} Type;
You do
char[26] string;
You'll need to add that into your typedef, I guess; or maybe "Void" is supposed to represented "void *", which this can be cast into.
ok, so I guess I should add an array of char here inside the typedef as well, am I right?
so I would have another type that says:
char[Integer]. so the typedef now will be:
Code:typedef enum {Void,Integer,Boolean,Char, Null, Char[Integer]} Type;
oh and one more off topic question, in C an int is compatible with char and vice versa, I don't really get this concept how is an int suppose to be compatible with a char and vice versa? can you give me an example?
what I have in head when I read this statement is the following would be valid:
int c = 'a'
but I don't think that's what it meant...
Of course that's valid -- but maybe not for the reason you expect. You probably expect 'a' to be of char type. But, in C, that's not true; 'a' is an int constant. (In C++ it is a char constant.)
But what it means to be compatible is that char, like short, long, and long long, are all integral types (they store integers). So when passing chars to printf, or doing arithmetic on chars, they get "promoted" to ints, temporarily.
and then so doing char b = 12;
is also valid in c?
so something like:
int test[200];
test[2] = 'a'
or
char foo[200];
foo['a'] = 55;
are both valid?
Yes...
Try it out for yourself.