Page 1 of 1

PostPosted: Thu Jan 18, 2007 12:49 pm
by jobie
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.)

-John