4 ms·
There are a few more faults in C that I would call out that make it actually a pretty bad low-level language: * No bitcast operator. Your options are a) use th
by jcranmer 8y ago
There are a few more faults in C that I would call out that make it actually a pretty bad low-level language:
* No bitcast operator. Your options are a) use the union trick; b) use the memcpy trick; or c) take an address, cast it to a different pointer type, and hope that your compiler gives you a pass on technically violating the standard here. Even C++ didn't get bitcast until C++20.
* No SIMD vector types. Of course, SIMD vectors are even more type-punning heavy than integers and floats, so you do need a good bitcast operator to get anywhere.
* Volatile and atomic are type qualifiers. These ought to be properties of the memory accesses; making them qualifiers on types obfuscates which memory accesses they apply to. If you look at the Linux kernel, it doesn't use volatile but instead uses a READ_ONCE macro that acts much like a volatile load.
* Bitfields are a mistake. They combine especially poorly with the vague properties of volatile. How many memory accesses are required in this program:
struct {
volatile unsigned a : 3;
volatile unsigned b : 2;
} foo;
foo.a = 3;
foo.b = 0;
- dooglius 8y ago> No SIMD vector types Huh? What architecture are you using that provides SIMD without corresponding vector types?