error C2628: '<unnamed-tag>' followed by 'bool' is illegal (did you forget a ';'?)

I am rewriting a program that was originally written using a helper class called genlib.h - described here http://www.keithschwarz.com/cs106l/winter20072008/handouts/020_Writing_Without_Genlib.pdf and documented here http://www.stanford.edu/class/cs106x/documentation/genlib_8h.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Type: bool
 * ----------
 * This type has two values, FALSE and TRUE, which are equal to 0
 * and 1, respectively.  Most of the advantage of defining this type
 * comes from readability because it allows the programmer to
 * provide documentation that a variable will take on only one of
 * these two values.  Designing a portable representation, however,
 * is surprisingly hard, because many libraries and some compilers
 * define these names.  The definitions are usually compatible but
 * may still be flagged as errors.
 */

#ifdef THINK_C
   typedef int bool;
#else
#  ifdef TRUE
#    ifndef bool
#      define bool int
#    endif
#  else
#    ifdef bool
#      define FALSE 0
#      define TRUE 1
#    else
       typedef enum {FALSE, TRUE} bool;
#    endif
#  endif
#endif 


this line of code "typedef enum {FALSE, TRUE} bool;" results in the error "error C2628: '<unnamed-tag>' followed by 'bool' is illegal (did you forget a ';'?)"

This is really confusing since this code has been around since 1994 and works fine, so why is the build puking this up now?
bool is a keyword in C++ so you can't use the same name for your own types.
Last edited on
why it a problem now?
Because you use C++ now, not C? The code is written to be used in C. C++ has it's own boolean data type called bool (same name as they try to name the enum type).
Last edited on
you are correct - I found a newer library on sourceforge
Topic archived. No new replies allowed.