Re:A Quiz About Integers in C
by JulianMorrison on Sunday June 03, 2012 @10:13PM
(#4062374)
Isn't the real answer to these questions "don't do that, you fool"?
[ Parent
| on HN ]
I think that answer deserves partial credit ;)
I believe that the reason people need to know these things is not because they should be playing Russian roulette with them, but because they need to know what's going on when things go accidentally wrong.
in theory yes, but often there are cases where you can't avoid mixing signed and unsigned stuff for example. Think about write() and read() syscalls that will return a signed type, but are often used in a context where buffer lengths are expressed in unsigned types.
Re:A Quiz About Integers in C
by JulianMorrison on Monday June 04, 2012 @09:16AM
(#4063823)
Then you probably want to mark it with an explicit function named something like "int32_to_uint32()" which you have defined (and debugged) in one place that performs the appropriate conversion with sanity checks.
Basically, IMO, C's implicit conversions are a flaw in the spec. A more sensible language would require every conversion (aside from those involving un-dimensioned constant data) to be spelled out explicitly. Since you can't make C sensible, the next best thing is to scrupulously isolate the stupid parts.