FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Architecture & Design
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
May 01, 2002
The New C:

bool, Advice to C and C++ Programmers

(Page 1 of 3)
Randy Meyers
True or False: The type bool behaves identically in C99 and C++. True or False: Your C89 bool hackery will survive unscathed under C99. Read and find out.
May 2002/The New C/Listing 1

Listing 1: My version of <stdbool.h>

/* An interim version of <stdbool.h> from C/C++ Users Journal
 * May 2002.  This file may be included from C90, C++, or C99
 * (but C99 should come with its own version).
 */

/* If C++, do nothing since bool is built in */
#if !defined(__cplusplus)

#  if !defined(__bool_true_false_are_defined)
#    define __bool_true_false_are_defined 1

     /* If this is C99 or later, use built-in bool */
#    if __STDC_VERSION__ >= 199901L
#      define bool _Bool
#    else
       /* Choose an unsigned type that can be used as a bitfield */
#      define bool unsigned char
#    endif

#    define true 1
#    define false 0
#  endif 

#endif /* !defined(__cplusplus) */

— End of Listing —
1 | 2 | 3 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.
DR. DOBB'S CAREER CENTER
Looking for a new job? open | close
Search jobs on Dr. Dobb's TechCareers
Function:

Keyword(s):

State:  
  • Post Your Resume
  • Employers Area
  • News & Features
  • Blogs & Forums
  • Career Resources

    Browse By:
    Location | Employer | City
  • Most Recent Posts:



    MICROSITES
    FEATURED TOPIC

    ADDITIONAL TOPICS

    INFO-LINK



     




    Techweb
    Informationweek Business Technology Network
    InformationweekInformationweek 500Informationweek 500 ConferenceInformationweek AnalyticsInformationweek Events
    Informationweek MagazineGlobal CIOIWK Government ITbMightyByte and SwitchDark Reading
    Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingPlug Into The CloudDr. DobbsContentinople
    space
    TechWeb Events Network
    InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0Mobile Business ExpoNoJitter
    Black HatGTECEnergy CampCloud ConnectGov 2.0 ExpoGov 2.0 Summit
    space
    Light Reading Communications Network
    Light ReadingLight Reading AsiaUnstrungCable Digital NewsInternet EvolutionPyramid Research
    Heavy ReadingLight Reading LiveLight Reading InsiderEthrnet ExpoTelco TVTower Technology Summit
    space
    Financial Technology Network
    Advanced TradingBank Systems and TechnologyInsurance and TechnologyWall Street and TechnologyAccelerating WallstreetBST SummitBuyside Trading SummitIT Summit
    space
    Microsoft Technology Network
    MSDNTechNetTotal IT ProTotal Dev ProNET Total Dev Pro CommunitySQL Total Dev Pro Community
    space