Thread: bool typedef and binary compatibility

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    5

    bool typedef and binary compatibility

    I was poring over some source code and came across the following:

    Code:
    /* Boolean type, assignment (but not necessarily binary) compatible with
     * C++ bool */
    typedef enum {sox_false, sox_true} sox_bool;
    I understand that this code creates a boolean (true or false) datatype but what does the author mean by his comment on the lack of binary compatibility with C++ bool.

    Does this mean that the C++ built-in bool usually compiles to a size of 1 byte whereas a C bool defined using and enumerated type is essentially an int and therefore usually 2 or 4 bytes in size?

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by BattlePanic View Post
    Does this mean that the C++ built-in bool usually compiles to a size of 1 byte whereas a C bool defined using and enumerated type is essentially an int and therefore usually 2 or 4 bytes in size?
    I think that's what it means.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, and enum's aren't necessarily binary compatible between different compilers, e.g. one compiler may decide to use short int (2 bytes), and another compiler uses a standard or long int (4 bytes).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. macros and size of
    By -EquinoX- in forum C Programming
    Replies: 6
    Last Post: 03-29-2008, 10:55 AM
  3. binary search tree help
    By noob2c in forum C++ Programming
    Replies: 6
    Last Post: 11-09-2003, 02:51 PM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM

Tags for this Thread