www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Size of D bool vs size of C++ bool

reply Jeremy DeHaan <dehaan.jeremiah gmail.com> writes:
I'm trying to do some binding code, and I know that C++ bool 
isn't defined to be a specific size like D's bool. That said, can 
I assume that the two are the same size on the most platforms?

The only platforms I'm really interested in are Windows, Linux, 
OSX, iOS, FreeBSD, Android. The only thing that might throw me 
off is if there are some things that Linux or FreeBSD target 
where this is not the case, but these machines are probably out 
of the scope of my project.
Aug 04 2017
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 8/4/17 4:16 PM, Jeremy DeHaan wrote:
 I'm trying to do some binding code, and I know that C++ bool isn't 
 defined to be a specific size like D's bool. That said, can I assume 
 that the two are the same size on the most platforms?
I shudder to think that D may work with a platform that doesn't consider it to be 1 byte :)
 The only platforms I'm really interested in are Windows, Linux, OSX, 
 iOS, FreeBSD, Android. The only thing that might throw me off is if 
 there are some things that Linux or FreeBSD target where this is not the 
 case, but these machines are probably out of the scope of my project.
I would say any platform that D currently supports, C++ bool is defined to be 1 byte. The ldc/gdc guys would know better. -Steve
Aug 04 2017
parent Jeremy DeHaan <dehaan.jeremiah gmail.com> writes:
On Friday, 4 August 2017 at 20:38:16 UTC, Steven Schveighoffer 
wrote:
 On 8/4/17 4:16 PM, Jeremy DeHaan wrote:
 I'm trying to do some binding code, and I know that C++ bool 
 isn't defined to be a specific size like D's bool. That said, 
 can I assume that the two are the same size on the most 
 platforms?
I shudder to think that D may work with a platform that doesn't consider it to be 1 byte :)
 The only platforms I'm really interested in are Windows, 
 Linux, OSX, iOS, FreeBSD, Android. The only thing that might 
 throw me off is if there are some things that Linux or FreeBSD 
 target where this is not the case, but these machines are 
 probably out of the scope of my project.
I would say any platform that D currently supports, C++ bool is defined to be 1 byte. The ldc/gdc guys would know better. -Steve
Thanks, Steve. I was hoping this was the case and it will significantly simplify a lot of my binding code. I'm curious to see what systems don't have a bool size of 1 byte, but perhaps I'll put a check in my CMake file and prevent the project from building if it isn't.
Aug 05 2017