bit on bool

B

bark

Given

class F
{
public:
bool a:1;
};

is there any point writing like this? I am refering to the "bool a:1;"

tia
Anders.
 
B

bark

Given

class F
{
public:
bool a:1;

};

is there any point writing like this? I am refering to the "bool a:1;"

tia
Anders.

humm.. after rereading my post maybe I should add some more
clarification:

in the original class where I found this it looks like

class F
{
<<...>>
bool a:1;
bool b:1;
bool c:1;
bool d:1;

<<some other declarations not bools and not using bitspec.>>
};

now I presume the author wanted to save some space - even though I
find it a bit pointless since it is not used in an application where
memory is critical but ok, I hadn't seen this way to write bool's
before.

So I was wondering what your take is on this? Is there some kind of
other benefit that I don't know about?

TIA
Anders again
 
A

ajk

* bark:










Might be efficiency, if these F's are passed around by value in zillions of
calls, or memory consumption if a quadzillion of them are in an array, or
matching layout of some lower level API or hardware.

Otherwise it just wastes both programmer and program time.

Difficult to say without more context info.

Cheers, & hth.,

- Alf

Thanks Alf,

the context is a compiler, so normally this would mean a one time
buildup of an abstract syntax tree where each tree node has 4 of these
bool's. I think we are talking about max a few thousand nodes so all
in all it seems useless.

br/Anders.
 
J

James Kanze

On Aug 13, 11:16 am, "Alf P. Steinbach" <[email protected]> wrote:

[...]
the context is a compiler, so normally this would mean a one
time buildup of an abstract syntax tree where each tree node
has 4 of these bool's. I think we are talking about max a few
thousand nodes so all in all it seems useless.

(More likely a few tens of thousands of nodes, or even hundreds
of thousands. But still a lot less that the zillions Alf
mentioned.)

It's probably a waste of time today. It might have been less
useless back in the days of 16 bit machines, and might be a
holdover from then. (While it wastes programmer time to write
it when you don't need it, if you already have it, it's probably
not worth the programmer time to change it.) Or just a
programmer who got into the habit back then, and hasn't evolved.
Conceivably, if there's a special allocator for F, which ensures
locality, it might reduce cache misses and page faults some, but
I'd be fairly surprised if it made a noticeable difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,466
Latest member
DrusillaYa

Latest Threads

Top