Using bool with MSVC++

This is a discussion on Using bool with MSVC++ within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to include stdbool.h in a C program I am writing using MSVC++. I get a fatal ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    62

    Using bool with MSVC++

    Hi,

    I am trying to include stdbool.h in a C program I am writing using MSVC++. I get a fatal error that it cannot open. No such file exists. I thought I needed to place it in the "stdafx.h" but that did not work either.

    What is my issue here?
    Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    That stdbool.h is a C99 header, and Microsoft will never support C99.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    62
    Thank you Salem.

    Is there any way to use boolean at all...another header...anything?

    Thanks

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    A couple of #defines (or an enum if you're feeling that way inclined), and any integral type work as a boolean in C.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    62
    Lost me.
    do you mean

    #ifndef FALSE
    #define FALSE 0
    #endif

    #ifndef TRUE
    #define TRUE 1
    #endif

    typedef int bool

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    62
    I am pretty new to this

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    That would work, though I'm unusure of what stdbool.h contains.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > do you mean
    Yes, that's exactly it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Maybe something like this would be better, in case you ever plan on updating the code to C++:

    Code:
    #ifndef __cplusplus
        typedef int bool;
    #   define true  1
    #   define false 0
    #endif

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    62
    thanks salem
    and cpjust

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    2,023
    Better to use an enum. It will give you better error messages:
    Code:
    #ifndef __cplusplus
    enum bool{
        false,
        true
    };
    #endif
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing params between managed c++ and unmanaged c++
    By cechen in forum C++ Programming
    Replies: 11
    Last Post: 02-03-2009, 07:46 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. Need Help With an RPG Style Game
    By JayDog in forum Game Programming
    Replies: 6
    Last Post: 03-30-2003, 07:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21