473,408 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

bit on bool

Given

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

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

tia
Anders.
Aug 13 '08 #1
3 1481
On Aug 13, 10:00*am, bark <ander...@gmail.comwrote:
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
Aug 13 '08 #2
ajk
On Aug 13, 11:16*am, "Alf P. Steinbach" <al...@start.nowrote:
* bark:
On Aug 13, 10:00 am, bark <ander...@gmail.comwrote:
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?

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.
Aug 13 '08 #3
On Aug 13, 6:05 am, ajk <ander...@gmail.comwrote:
On Aug 13, 11:16 am, "Alf P. Steinbach" <al...@start.nowrote:
[...]
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.>>
};
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.
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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Aug 13 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pierre Espenan | last post by:
A have a long integer class. The built integer type within a conditional statement returns bool false for int i=0 and bool true for any other non zero value. I want my long integer class to have...
4
by: Nomak | last post by:
Hello, With this code: $ cat -n ifs.cc 1 #include <vector> 2 #include <iostream> 3 4 using std::vector; 5 using std::cin;
19
by: daniel | last post by:
1) is C++ smart enough to automatically use "bits" for bool or will a bool have the size of a charcter (byte). 2) The index of a vector is it an integer (4 byte) or a "long long" with 8 bytes or...
4
by: ORC | last post by:
Is the bool type actually an Int32 with 0 as false and non zero as true? The reason for my question is that I've seen a lot of API calls that return a Int32 implemented in C# as an bool like: ...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
1
by: Bern McCarty | last post by:
What do you make of this? I cannot tell for sure but it almost seems as the the transition thunk to get back from the native bool method to the managed caller is looking at eax and, if any bit is...
4
by: gpg | last post by:
I am using a legacy DLL and need to marshal some structures for use in the DLL. For the most part, I have figured out my needs except for one small item. I have a structure that contain, among...
6
by: zl2k | last post by:
hi, there I am using a big, sparse binary array (size of 256^3). The size may be changed in run time. I first thought about using the bitset but found its size is unchangeable. If I use the...
64
by: shaanxxx | last post by:
I have code which says #define MYBOOL int This code is very old. people who have written is not avaible. I was thinking what could be reason. 1) bool datatype was not available that time (10...
3
by: markb | last post by:
Hi My C# app is being called from a callback from an unmanaged DLL. One of the parameters of the callback is of type BOOL. I am using PInvoke to marshal this to a (managed) bool. The problem is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.