474,011 Members | 6,052 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Absense of bool

First of all: I love C and think that it's beautiful. However, there is
at least one MAJOR flaw: the lack of a boolean type.

OK. Some of you might refer to C99 and its _Bool (what's up with the
uppercase 'B' anyway?) and the header you can include (apparently) to
get a real "bool". This isn't my point, however -- it should have been
there from the beginning.

Char is a small int. We all know that. However, "char some_bool = 0;"
simply feels wrong, and I think that most of you agree. Plus, it's
still too large.

"int some_bool = 0;" is what I -- and everyone else, I assume -- use
for bools. But an int is a very large data type for something that will
only ever be true or false (1 or 0). This really, really bugs me.

Why, back when C was designed, didn't they see a reason to build in a
boolean type into the language? Now it matters less, I guess, but back
then, there should have been very strong technical reasons. It just
doesn't make any sense whatsoever to me.

I have asked many people about this for quite some time, and they are
all just telling me that I'm silly for bringing it up. Why? It's not
that I NEED a bool to get anything done -- it's the principle. Saving
resources and coding a little more prettily is a Good Thing (TM) IMO.

So... can somebody properly explain this to me once and for all? I'm
sure there MUST be a logical explanation that nobody seems to really
understand. The madness must end.

bool some_bool = 0; /* How great it would be... */

Nov 3 '07
51 2975
AommiK wrote:
I have asked many people about this for quite some time, and they are
all just telling me that I'm silly for bringing it up. Why? It's not
that I NEED a bool to get anything done -- it's the principle. Saving
resources and coding a little more prettily is a Good Thing (TM) IMO.
If the point is just pretty coding, then:
typedef int bool;

Or better:
typedef unsigned bool;
(Operations on unsigned values are often less expensive than signed ones)

JJ
Nov 5 '07 #31
João Jerónimo wrote:
AommiK wrote:
>I have asked many people about this for quite some time, and they are
all just telling me that I'm silly for bringing it up. Why? It's not
that I NEED a bool to get anything done -- it's the principle. Saving
resources and coding a little more prettily is a Good Thing (TM) IMO.

If the point is just pretty coding, then:
typedef int bool;

Or better:
typedef unsigned bool;
(Operations on unsigned values are often less expensive than signed ones)
They are?

Which operations, how much, and how often?

--
Chris "afflicted with a failure of imagination" Dollin

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Nov 5 '07 #32
On Monday 05 Nov 2007 10:22 pm Richard <rg****@gmail.c omwrote in
article <qb************ @news.individua l.net>:
João Jerónimo <j_*******@yaho o.com.brwrites:
<snip>
> - C doesn't have built-in Garbage Collection because ASM languages
don't
support the concept either.

No, C doesnt have it because it didnt exist when C was invented and it
makes a mockery of efficiency IMO.
No. Garbage collection existed before C. LISP had it.

<snip>
Nov 5 '07 #33
Chris Dollin wrote:
>Or better:
typedef unsigned bool;
(Operations on unsigned values are often less expensive than signed ones)

They are?

Which operations, how much, and how often?
In reality, they don't matter for bools...

Multiplications and divisions.

JJ
Nov 5 '07 #34
On Monday 05 Nov 2007 10:59 pm João Jerónimo <j_*******@yaho o.com.br>
wrote in article <47************ ***********@new s.sunsite.dk>:
Richard wrote:
>João Jerónimo wrote:
>> - C, natively, only knows how to deal with logical and arithmetic
data. That's because most processors only know that.

Is this without the standard library?

No! Don't tell me that C needs the standard library to do arithmetic!
I don't think so!
Some arithmetic operations may however be implemented as "magic"
function calls, essentially compiler magic, invisible from the
standpoint of Standard C. Extended width arithmetic is typically done
this way.

<snip>

Nov 5 '07 #35
santosh wrote:
On Monday 05 Nov 2007 10:22 pm Richard <rg****@gmail.c omwrote in
article <qb************ @news.individua l.net>:
>João Jerónimo <j_*******@yaho o.com.brwrites:

<snip>
>> - C doesn't have built-in Garbage Collection because ASM languages
don't
support the concept either.
No, C doesnt have it because it didnt exist when C was invented and it
makes a mockery of efficiency IMO.

No. Garbage collection existed before C. LISP had it.

<snip>
I'm shocked! Can it be true that someone actually reads post from
rg****@gmail.co m?
Nov 5 '07 #36
João Jerónimo wrote, On 05/11/07 17:49:
Chris Dollin wrote:
>>Or better:
typedef unsigned bool;
(Operations on unsigned values are often less expensive than signed ones)
They are?

Which operations, how much, and how often?

In reality, they don't matter for bools...

Multiplications and divisions.
On the processors where I have had an interest in the speed those were
no slower for signed than for unsigned. This shows that at the very
least your assertion is not true for all implementations .
--
Flash Gordon
Nov 5 '07 #37
Martin Ambuhl wrote:
santosh wrote:
>Richard <rg****@gmail.c omwrote:
.... snip ...
>>
>>No, C doesnt have it because it didnt exist when C was invented
and it makes a mockery of efficiency IMO.

No. Garbage collection existed before C. LISP had it.

<snip>

I'm shocked! Can it be true that someone actually reads post from
rg****@gmail.co m?
Once in a while I find he has made a direct reply to me (which
hasn't been quoted) and become curious about any improvement. Then
I mark that reply unread, and my next connection to the news-server
gets it. In general I find no improvement.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 6 '07 #38
João Jerónimo <j_*******@yaho o.com.brwrites:
Richard wrote:
<snip (some attribution manual replaced)>
>>João Jerónimo <j_*******@yaho o.com.brwrites:
>> - C doesn't have built-in Garbage Collection because ASM languages don't
support the concept either.

No, C doesnt have it because it didnt exist when C was invented and it
makes a mockery of efficiency IMO.

Yes.
<snip>
- And, of course, it didn't exist when C was invented
Marvin L. Minsky. A Lisp garbage collector algorithm using serial
secondary storage. Technical Report Memo 58 (rev.), Project MAC, MIT,
Cambridge, MA, December 1963.

I don't claim that this is the first paper on GC, just that it
pre-dates C. There are dozens of papers about GC from the 60s and DMR
cites 1969-73 as the key design time for C.

--
Ben.
Nov 6 '07 #39
Ben Bacarisse <be********@bsb .me.ukwrites:
João Jerónimo <j_*******@yaho o.com.brwrites:
>Richard wrote:
<snip (some attribution manual replaced)>
>>>João Jerónimo <j_*******@yaho o.com.brwrites:
- C doesn't have built-in Garbage Collection because ASM languages don't
support the concept either.

No, C doesnt have it because it didnt exist when C was invented and it
makes a mockery of efficiency IMO.

Yes.
<snip>
> - And, of course, it didn't exist when C was invented

Marvin L. Minsky. A Lisp garbage collector algorithm using serial
secondary storage. Technical Report Memo 58 (rev.), Project MAC, MIT,
Cambridge, MA, December 1963.

I don't claim that this is the first paper on GC, just that it
pre-dates C. There are dozens of papers about GC from the 60s and DMR
cites 1969-73 as the key design time for C.
What languages used GC at the time that C and its forefathers were
evolving? How do you see GC fitting into the "style" of C?

Putting GC into C would have been like interpreting assembler IMO ....
Nov 6 '07 #40

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

Similar topics

3
2623
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 similar behavior. My class looks like this: #ifndef long_int_H #define long_int_H #include <string> using namespace std; typedef valarray<complex<double> > VCD;
19
3395
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 something else? I ask because I want to use vector<bool> with a few billion entries exceeding the int32 range for indexing and I want to use as few memory as possible for the whole
4
10771
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: private static extern bool PurgeComm( Int32 hFile, UInt32 dwFlags); Thanks Ole
6
6876
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 vector<bool>, does each element takes 4 bytes instead of 1 bit? I am using gcc3.4.4. There is a bit_vector which is kind of old so I wont use that. Any other choices? Thanks ahead. zl2k
64
3951
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 years back: correct me if i am wrong) 2) int was word aligned (16bit and 32bit). Writter of above code doesnt want to give choice to compiler.
3
6342
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 that no matter if we pass TRUE or FALSE, the bool is always marshalled as true. // unmanaged code in dll typedef bool (__stdcall *BoolCallBack)(short b);
0
10271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12001
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11528
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
11037
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10207
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8599
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7745
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
5299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.