AommiK said:
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.
Why a major flaw? What do you need the concept of boolean type in C for?
Anyway, if you really NEED it, you can always typedef it.
It would just complicate things. Besides, it's just against the design
principle of C.
C just implements some basic abstractions in order to make it easy to
program in low level. It abstracts variables, functions, static memory
structures (structs and arrays) and algorithms. JUST that!
It doesn't even define I/O resources. All that (including dynamic
allocation) is defined/implemented by the Standard Library (which is not,
strictly, part of the language / indeed, you can replace the C standard
library, create your own and use it in your program).
C is not a portable assembly. However, it is a language that works *like*
assembly. It's not meant to extend assembly, but only to provide a portable
and more structured equivalently featured language. It picks a number of
rules that, generally, any serious ASM program needs to follow (like being
logically separated in procedures, carefully allocating meaningful
variables across registers and memory, establishing uniform calling
conventions, putting sequentially accessed data in neighbor memory
addresses, not doing self-modifying code tricks, etc), and adds them to the
core language to save the programmer from having to follow them.
Additionally, it abstracts the processor's Instruction Set in order to
allow you to describe algorithms machine-independently.
- C has pointers because machine code needs pointers.
- In C, an array is represented as a pointer to it's first element
because, in ASM, arrays are represented and manipulated like that.
- C, natively, only knows how to deal with logical and arithmetic data.
That's because most processors only know that.
- C doesn't have built-in Garbage Collection because ASM languages don't
support the concept either.
- C doesn't have dynamic typing simply because there's no direct way to
tell the type of a data structure in machine code.
- C integers overflow because integers, in ASM, overflow too...
- Like above, C doesn't have a boolean data type because processors
emulate boolean values with (modular) integers, too. The exception may be,
perhaps, bit-addressed machines (I don't know, never programmed one)...
That doesn't mean that you are limited to what the language offers you.
Just like what happens in assembly, you can always extend the language at
your will. (of course, you can still do much more in assembly, but it's
generally special purpose)
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.
But THAT's the point.
C is very extensible through the library (and again, just like it happens
to be in assembly).
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.
Nope... Unless you want a bit field (in order to have many bools inside a
byte), it's much more efficient to manipulate entire words instead of chars...
Even if you save some space, the processor will need to sign extend the
byte in order to work with it.
JJ