FYI - bool vs. char

Discuss OrbForms Designer and PocketC Architect

Postby jobie on Thu Jan 18, 2007 12:49 pm

I just encountered a problem (of my own design) and thought I'd let everyone know about it in case you run into a similar situation.

I was reading and writing a fairly complex database record structure, created with orbpdb. I have a bunch of 1-byte fields that I intend to use as booleans. Of course, in a CSV file the smallest atomic unit is a byte. So in my structure, I let those fields be bools, since sizeof(bool) == 1.

My problem happened when I was reading the records...the fields were coming up partly ok, but there was definitely some funky misalignment happening at certain times.

Switching all the bools to chars fixed the problem.

My guess is sizeof(bool) cannot return the accurate size since a bool is 1/8 of a byte. (I had assumed Jeremy had taken the easy way out and basically typedef'd a bool to an char.)

Posts: 23
Joined: Wed Dec 27, 2006 8:53 pm
Location: USA

Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 2 guests