0

My Solution consists of Multiple C++ and one C project using VS 2015.

I am getting error error C2632: 'int' followed by 'bool' is illegal on following line of code in C header file.

#ifndef __cplusplus
typedef int bool;
#endif 

this code was working fine in VS 2013

Any idea what could be the reason?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
  • 5
    Because C has a boolean type since ca. 17 years? Good to see MS also heard that finally. See `stdbool.h` – too honest for this site Feb 15 '16 at 16:19
  • Thanks Olaf stdbool.h worked. I removed the above code and included stdbool.h – Saifullah Zahid Feb 15 '16 at 16:27
  • @Saifullah Zahid It is a wrong statement that C has a boolean type. C does not have a boolean type. C has integer type _Bool that has nothing common with type bool. The reason for the error can be either a bug of the compiler or there is already a typedef for name bool that uses a different type specifier. as for example typedef _Bool bool; – Vlad from Moscow Feb 15 '16 at 16:39
  • 1
    @VladfromMoscow Was it not [added in C99](http://stackoverflow.com/a/1608350/4892076) as part of the C standard library header ? While it's not a keyword, it is reserved. From 7.26.7: "The ability to undefine and perhaps then redefine the macros `bool`, `true`, and `false` is an obsolescent feature." – jaggedSpire Feb 15 '16 at 16:48
  • @jaggedSpire First of all you have at first to include the header . I am sure that the author of the question does not use it. And secondly "obsolescent feature" means in fact nothing. – Vlad from Moscow Feb 15 '16 at 16:56
  • @Vlad from Moscow Concerning "C does not have a boolean type." --> The C11 spec has "7.18 **Boolean type** and values " ... The macro `bool` expands to `_Bool` ... Is the C committee wrong in calling that a boolean type? – chux - Reinstate Monica Feb 15 '16 at 17:09
  • @chux I am sure that the committee is wrong or uses this term in a very broad meaning. And there is no such type specifier as bool. Moreover in my first comment that you should reread one more I already wrote that bool can be a typedef for example for _Bool or other type. So your comment does not make any sense. – Vlad from Moscow Feb 15 '16 at 17:13
  • 1
    @Vlad from Moscow Sounds like we agree there is a type `_Bool` in C. And I am sure you agree `_Bool` can have 1 of 2 values (C11 6.2.5). To me, that sounds like a [boolean type](https://en.wikipedia.org/wiki/Boolean_data_type). So the comment "C does not have a boolean type." appears inconsistent, hence the comment. – chux - Reinstate Monica Feb 15 '16 at 17:22
  • @chux There is a contradiction in the C Standard. Type _Bool belongs to unsigned integer types that stores two integer constant 1 and 0. Moreover I even do not know what built-in logical operator returns this "boolean" type. – Vlad from Moscow Feb 15 '16 at 17:30
  • @VladfromMoscow: FYI: In C, logical and comparison operators yield an `int` result (very likely for legacy reasons). See [6.5.13p3](http://port70.net/~nsz/c/c11/n1570.html#6.5.13p3) and the other operators. – too honest for this site Feb 15 '16 at 18:21
  • https://en.wikipedia.org/wiki/Boolean_data_type – too honest for this site Feb 15 '16 at 18:32

0 Answers0