3 ms·
The C type conversions I know of seem quite trivial. Can you give an example of something non-trivial? And I don't mean something like the float f = some_intege
by DeepDuh 14y ago
The C type conversions I know of seem quite trivial. Can you give an example of something non-trivial? And I don't mean something like the float f = some_integer / some_other_integer trap, those should be obvious.
- gurkendoktor 14y agoThe automatic dereferencing in "pointerToStruct.foo" might have to loop until it arrives at a struct. I think such a loop would be unique in C, but I don't feel it'd make C any higher level. Similar in concept: &function and function are the same. If you have a fixed-size array: ary, &ary and ary[0] are the same when passing them into a function. Then there are all the other numeric conversions, where "unsigned" is a common trap, and truthiness. Even if most conversions are trivial, I wouldn't call C a very explicit language. Compared to what?
- to3m 14y agopointerToStruct.foo would just be equivalent to pointerToStruct->foo. No loop required. The main problem with this is that it hides memory accesses. The offset of x.y.z.w relative to &x can be determined at compile time, so if &x is available, accessing x.y.z.w requires roughly only one load instruction. (DISCLAIMER: ABI- and compiler-dependent. One instruction is an estimate. This estimate may not be precisely true for all possible programs across all CPUs and compilers.) But x->y->z->w requires 3 pointer dereferences, even if you have x to hand. 3 load instructions and therefore 3 memory accesses. (The same disclaimer applies.) People already complain enough about the inefficiency of C++ operator overloading, and the difficulty of spotting when it occurs just by examination of the source code... Additionally, this change wouldn't play nicely with C++ operator overloading. I just set up my text editors to insert -> when I press <Alt-,>.
- gurkendoktor 14y agoI assumed that arbitrary levels of indirection would be flattened, hence a loop. I'm not asking for this feature, I'm only arguing that C was never explicit to begin with. For example, you cannot tell how many indirections happen in a[5][2][8] either. Every game programmer must have seen a newbie try to cast a[4][4] into a :)