Thread: Visual Studio 2010 and stdbool.h

  1. #16
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Elysia View Post
    That's because they are keywords in C++. But they are not for C, so you have to define them.
    Something like
    Code:
    #ifndef __cplusplus
    #define TRUE 1
    #define FALSE 0
    #endif
    Why define them in caps? I know that's how macros are usually defined, but if you define them as true & false instead, then it would be easier to port the code to C++ later wouldn't it?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  2. #17
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    If you are doing embedded, it might be a good idea to switch to GCC.

    Most embedded compilers are based on GCC, and it does support C99.

    Visual Studio gives you better Windows support, but well, you are not coding for Windows.

  3. #18
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Why not just
    typedef char bool;
    ?

    Why use 4 bytes (possibly) when only 1 is required? I never understood why int is used for bools.
    Because of this. keyword here is 'maybe'.
    Last edited by Bayint Naung; 07-02-2010 at 01:14 AM.

  4. #19
    Registered User
    Join Date
    Jun 2010
    Posts
    19
    Quote Originally Posted by cyberfish View Post
    If you are doing embedded, it might be a good idea to switch to GCC.

    Most embedded compilers are based on GCC, and it does support C99.

    Visual Studio gives you better Windows support, but well, you are not coding for Windows.
    I used Dev-C++ first, but ran into some problems with it and decided to go back to Visual Studio, since I know Visual Studio so much better otherwise.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Bayint Naung View Post
    Because of this. keyword here is 'maybe'.
    I see only pessimistic optimization.
    Actually, I like the bool enum idea:
    Code:
    enum bool { false, true };
    In normal case, I wouldn't like the idea that it spits out the contents in the global namespace, but this is exactly what is necessary in this case. Plus it defines the type bool.
    Why didn't I think of this earlier?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User
    Join Date
    Jun 2010
    Posts
    19
    Quote Originally Posted by Jaymond Flurrie View Post
    I used Dev-C++ first, but ran into some problems with it and decided to go back to Visual Studio, since I know Visual Studio so much better otherwise.
    Just remembered why I changed away from Dev-C++. It had that
    "'for' loop initial declaration used outside C99 mode" error,
    so I didn't see any advantages using Dev-C++ over VS2010.

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Dev-C++ is bad. It's not maintained anymore AFAIK.
    Better use Code::Blocks if you need C99 compatibility (with gcc compiler).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    There's just no pleasing some people

    > typedef char bool;
    > ?
    > Why use 4 bytes (possibly) when only 1 is required? I never understood why int is used for bools.

    Later....
    > Actually, I like the bool enum idea:

    enums in C ARE integers.
    Incompatibilities Between ISO C and ISO C++

    > "'for' loop initial declaration used outside C99 mode" error,
    Depending on which version of gcc you end up with, you might need to set it so that you do
    gcc -std=c99 prog.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.

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Salem View Post
    I know, but it avoids macros, which IMO makes it a better alternative.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed