I don't even understand, given the statements you (@DiTBho) make on various programming topics, why you even bother with C. It clearly doesn't match your expectations/requirements.
Because things like sizeof(x) are really a stupid things in the way they have been implemented, and -
here the annoying + frustrating part is that - it's would be extremely easy for competent people to be fixed them, but people argument that it's ok.
Why People don't fix it once and forever in say "
C-2022" revision instead than introducing more stupid workarounds? I cannot believe "
because otherwise it won't compile for PDP/8"
For the records, I have designed my own C-like compiler targetting MIPS4-only and
sizeof(type) has been renamed byte_sizeof(type), which always returns things measured in byte
char, short, int, long, long long are banned so you cannot use them
It doesn't need any external header to *redefine* the basic data-types
char8_t (always unsigned, and always 8bit, it's for ASCII stuff)
char16_t (always unsigned, and always 16bit, it's for unicode stuff)
uint8, uint16, uint32, uint64,
sint8, sint16, sint32, sint64,
fp32, fp64, fx1616, fx2408,
cplxfp32, cplxfp64, cplxfx1616, cplxfx2408, (complex numbers)
p_uint8, p_uint16, p_uint32, p_uint64, (p_ means pointer)
p_sint8, p_sint16, p_sint32, p_sint64,
p_fp32, p_fp64, p_fx1616, p_fx2408,
p_cplxfp32, p_cplxfp64, p_cplxfx1616, p_cplxfx2408,
p_this, p_that (like void*)
p_char8
p_char16
string8 (this is like p_char8, but the first cell stores the length)
string16 (this is like p_char16, but the first cell stores the length)
There is also boolean, which is a true type with its logic operators
(p_boolean is its pointer)
All of these are built-in, you don't need any header (perpetually wrong, bugged, wrong) header.
I am so frustrated with the all the shit done by GNU with their
glibc headers, always broken, always with problems because the last hacker decided to change something; supporting them on Gentoo is
more frustrating than thinking you can cool hell, and this because people continuously modify those bloody headers and you have no more compiling stuff, or worse still, broken stuff, and this because people continuously modify those bloody headers and you have no more compiling stuff, or worse still, broken stuff.
Is it reasonable? I don't think so! And here, see my simple solution:
my MIPS4 prototype doesn't implements 16 bit operations (some instructions are missing in hardware), Gcc doesn't fully support a MIPS4 cpu like R18K (which is not officially existing, anyway, the last one was R16K, and the last supported was R12K)
So, I applied these nazy rules:
unt16, sint16, p_uint16, p_sint16 are
NOT defined, and there is no way to define them, so the user cannot mess up anything!
Do you see how coherent, simple, elegant it is?
You have a piece of C code where you see "uint16_t ", the compiler won't accept it and returns
"
sorry, this target doesn't support 16 bit datatype"
Which is super-clear, simple, and not bug-prone.
Applied to TI320, ... "char" is banned, the compiler doesn't accept it, you have to use "char8" or "char16", and when you try to define "char8 something"
"
sorry, this target doesn't support 8 bit datatype"
I have these operators
bit_sizeof(type), returns the size of a type in bits, e.g. sizeof(uint8_t) returns 8
byte_sizeof(type), returns the size of a type in byte (byte=8bit), e.g. sizeof(uint8_t) returns 1
typeof(type), returns the type (grabbed from the typedef-space), that's super useful for polymorphic code
switch (typeof(type))
{
case fx2408:
...
break;
case fx1616:
...
break;
...
}
case can be of any type, you can compare strings, fp numbers, etc
logicalExOr ^^ is not defined by C, and again you have to provide an header with this difinition
#define logicalExOr(A, B) ((!A) != (!B)) // new
#define logicalExNOr(A, B) ((!A) == (!B)) // new
My compiler comes with a built-in logicalExOr operator, which ONLY works on boolean stuff.
If you try to apply it to say "uint8" it will trigger an error.
Anyway, I cannot call my compiler "C", it's not C-compliant in several aspects, but who cares? Gcc can compile my compiler and it works on HPPA, and I am able to (cross)compile on an HPPA workstation an hacked version of XINU(1) for a MIPS4 prototype.
(the generated machine-code sucks about optimization, I know ... , but) next step, re-targeting for 68K
- in Conclusion -I hope someone with more skills and attributes than me will one day take all the bullshit out of C and fix it right once and for all without making C too big like C++
(1) Written in C89, rewritten in "myC". It tooks a bit because I also cleaned it a bit, but it was not a difficult task.