--- In [email protected], "thos_fernando" <[EMAIL PROTECTED]> wrote:
>
> Hi ,
> I came across a C statement as below.
> typedef enum {False, True} boolean;
> I was wondering if someone could explain how this would
> work,preferably with an example.
> I know that
> typedef enum {False,True}; would mean that False=0 and True=1.
> How does the word boolean play a part ?AFAIK boolean is not a C
> keyword.How would this be used while programming ?
Hi Thomas,
that's easy. The "typedef" keyword tells the compiler that from this
point onward (subject to scope rules, but that's a different matter)
the term "boolean" will always mean "enum {False, True}". "typedef" is
used to create a new name for a particular type.
An easy example: Usually in C you would have to write
enum {False, True} flag1;
enum {False, True} flag2;
enum {False, True} flag3;
now with this new name for the type you can simply use:
boolean flag1;
boolean flag2;
boolean flag3;
which makes your code easier to read (and safer against some typos).
Does that answer your question?
Regards,
Nico