locked
Is bool a built-in type of C/C++? RRS feed

  • Question

  • Hi,

     

    I would like to ask a question on C data type.

    Is boolean a basic data type or C? I have found that some compilers other than Visual C++ doesn’t support bool or Boolean, and according to page 35 of Kernighan & Ritchie - The C Programming Language (2ed), perhaps boolean types are not among the built-in data types.

    However, in MSDN bool is listed as a built-in type.

     

      

     

    So is this Microsoft’s extension to the original C/C++?

     

    Bob

     


    • Edited by Bob Sun Saturday, October 1, 2011 3:05 PM
    Saturday, October 1, 2011 3:04 PM

Answers

  • Yes, bool is built-in data type in C++ but not in C.  Believe your eyes.

     -- pa

    • Edited by Pavel A Saturday, October 1, 2011 3:41 PM
    • Marked as answer by Bob Sun Saturday, October 1, 2011 3:52 PM
    Saturday, October 1, 2011 3:41 PM
  • See Wikipedia for details on boolean type and C "The initial standards for the C language (1972) provided no Boolean type; and, to this day, Boolean values are commonly represented by integers (ints) in C programs.": http://en.wikipedia.org/wiki/Boolean_type#History.

    In C++ it was introduced in 1993: http://www.glenmccl.com/bool_cmp.htm.

    Also: http://stackoverflow.com/questions/356726/is-bool-a-basic-datatype-in-c

    I can add that you can find old programs in C++ where boolean type is represented by enumeration. Like:

     enum Bool {false, true};

    • Marked as answer by Bob Sun Saturday, October 1, 2011 5:17 PM
    Saturday, October 1, 2011 4:00 PM
  • Here's another one  http://en.wikipedia.org/wiki/Stdbool.h

    -- pa

    • Marked as answer by Bob Sun Sunday, October 2, 2011 4:48 PM
    Sunday, October 2, 2011 11:47 AM
  • This page on VC++ 2010:

    http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.100).aspx

    says:

    "This version of Visual C++ is not conformant with the C99 standard."

    Some discussion of the rationale can be found in this blog:

    ISO C Standard Update
    http://blogs.msdn.com/b/vcblog/archive/2007/11/05/iso-c-standard-update.aspx

    Excerpt:

    "Now, the Visual C++ compiler team receives the
    occasionally (sic) question as to why we haven't
    implemented C99.  It's really based on interest
    from our users.  Where we've received many requests
    for certain C99 features, we've tried to implement
    them (or analogues).  A couple examples are variadic
    macros, long long, __pragma, __FUNCTION__, and __restrict.
    If there are other C99 features that you'd find useful in
    your work, let us know!  We don't hear much from our C
    users, so speak up and make yourselves heard."

    And here:

    http://connect.microsoft.com/VisualStudio/feedback/details/512131/why-not-support-c99

    - Wayne
    • Marked as answer by Bob Sun Wednesday, October 5, 2011 5:32 PM
    Tuesday, October 4, 2011 7:55 PM
  • On 10/5/2011 10:48 AM, Bob Sun wrote:

    There seems to be at present two popular C++ specifications:
    ISO_IEC_14882-1998 and ISO_IEC_14882_2003. Do you know which version
    of VC++ support which? Is there a Microsoft site containing this
    information?

    There's very little difference between the two. VC7.1 through VC9 support C++03 (VC10 adds some elements of C++11). VC6, released in 1998, is basically not standard-conformant. C++98 is largely of historic interest nowadays (but again, there are really no major changes between C++98 and C++03).


    Igor Tandetnik

    • Marked as answer by Bob Sun Wednesday, October 5, 2011 6:06 PM
    Wednesday, October 5, 2011 5:06 PM

All replies

  • Pavel,

    I think it is correct. Thanks.

    Bob

    Saturday, October 1, 2011 3:52 PM
  • See Wikipedia for details on boolean type and C "The initial standards for the C language (1972) provided no Boolean type; and, to this day, Boolean values are commonly represented by integers (ints) in C programs.": http://en.wikipedia.org/wiki/Boolean_type#History.

    In C++ it was introduced in 1993: http://www.glenmccl.com/bool_cmp.htm.

    Also: http://stackoverflow.com/questions/356726/is-bool-a-basic-datatype-in-c

    I can add that you can find old programs in C++ where boolean type is represented by enumeration. Like:

     enum Bool {false, true};

    • Marked as answer by Bob Sun Saturday, October 1, 2011 5:17 PM
    Saturday, October 1, 2011 4:00 PM
  • Sergey,

    The links are helpful. Thanks very much.

    Bob

    Saturday, October 1, 2011 5:18 PM
  • Pavel,

     

    Thanks, I checked stdbool.h and it was indeed in ISO-9899-1999 standard.

     

    Bob

    Sunday, October 2, 2011 4:49 PM
  • Bob Sun wrote:
    >
    >Thanks, I checked stdbool.h and it was indeed in ISO-9899-1999 standard.
     
    Yes, but remember that Visual C++ does not implement the 1999 C standard.
    It still conforms to the 1989 standard.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.
    Tuesday, October 4, 2011 3:08 AM
  • Tim,

    This is important. Could you provide a link to a Microsoft official statement on this point?

     

    Bob

    Tuesday, October 4, 2011 7:05 PM
  • This page on VC++ 2010:

    http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.100).aspx

    says:

    "This version of Visual C++ is not conformant with the C99 standard."

    Some discussion of the rationale can be found in this blog:

    ISO C Standard Update
    http://blogs.msdn.com/b/vcblog/archive/2007/11/05/iso-c-standard-update.aspx

    Excerpt:

    "Now, the Visual C++ compiler team receives the
    occasionally (sic) question as to why we haven't
    implemented C99.  It's really based on interest
    from our users.  Where we've received many requests
    for certain C99 features, we've tried to implement
    them (or analogues).  A couple examples are variadic
    macros, long long, __pragma, __FUNCTION__, and __restrict.
    If there are other C99 features that you'd find useful in
    your work, let us know!  We don't hear much from our C
    users, so speak up and make yourselves heard."

    And here:

    http://connect.microsoft.com/VisualStudio/feedback/details/512131/why-not-support-c99

    - Wayne
    • Marked as answer by Bob Sun Wednesday, October 5, 2011 5:32 PM
    Tuesday, October 4, 2011 7:55 PM
  • Also see:

    C++11 Features in Visual C++ 11
    http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx

    Excerpt:

    "... VC11 won't completely implement the C99 Standard Library,
    which has been incorporated by reference into the C++11
    Standard Library."

    - Wayne
    Tuesday, October 4, 2011 9:09 PM
  • Wayne,

    Thanks for the link and information.

    There seems to be at present two popular C++ specifications: ISO_IEC_14882-1998 and ISO_IEC_14882_2003. Do you know which version of VC++ support which? Is there a Microsoft site containing this information?

     

    Bob

     

    Wednesday, October 5, 2011 2:48 PM
  • On 10/5/2011 10:48 AM, Bob Sun wrote:

    There seems to be at present two popular C++ specifications:
    ISO_IEC_14882-1998 and ISO_IEC_14882_2003. Do you know which version
    of VC++ support which? Is there a Microsoft site containing this
    information?

    There's very little difference between the two. VC7.1 through VC9 support C++03 (VC10 adds some elements of C++11). VC6, released in 1998, is basically not standard-conformant. C++98 is largely of historic interest nowadays (but again, there are really no major changes between C++98 and C++03).


    Igor Tandetnik

    • Marked as answer by Bob Sun Wednesday, October 5, 2011 6:06 PM
    Wednesday, October 5, 2011 5:06 PM
  • Wayne,

    These links are informative. Thanks.

     

    Bob

    Wednesday, October 5, 2011 5:34 PM
  • Igor,

    I see it, thanks for the answer.

    Bob

    Wednesday, October 5, 2011 6:06 PM