C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-08-2008, 06:54 AM   #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?
BattlePanic is offline   Reply With Quote
Old 05-08-2008, 07:19 AM   #2
and the hat of sweating
 
Join Date: Aug 2007
Location: Toronto, ON
Posts: 3,120
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.
cpjust is offline   Reply With Quote
Old 05-08-2008, 08:04 AM   #3
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Reply

Tags
enum bool typedef binary

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Polynomials and ADT's Emeighty C++ Programming 20 08-19-2008 08:32 AM
macros and size of -EquinoX- C Programming 6 03-29-2008 10:55 AM
binary search tree help noob2c C++ Programming 6 11-09-2003 02:51 PM
Headers that use each other nickname_changed C++ Programming 7 10-03-2003 04:25 AM
BST/Red and Black Tree ghettoman C++ Programming 0 10-24-2001 10:45 PM


All times are GMT -6. The time now is 10:16 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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