Timeline for Why are there so few C compilers?
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 20, 2015 at 17:55 | comment | added | supercat |
@Morwenn: For many C programs, Undefined Behavior. If short is half the length of long, for example, (unsigned short)(-1)*(unsigned short)(-1) will yield full-fledged Undefined Behavior, since the unsigned short values will get promoted to signed int values which, when multiplied, will exceed the range of the signed int type; a compiler is allowed to do anything it likes in response to such overflow, including launching a virus to target and destroy all copies of the painting "Dogs Playing Poker".
|
|
Feb 20, 2015 at 16:48 | comment | added | Morwenn | That's implementation-defined behaviour, not undefined behaviour. | |
Feb 19, 2015 at 18:37 | comment | added | Doval | @MSalters There's enough leeway in the size of the standard types and enough implicit conversions that I'd bet that for just about any non-trivial C program there's a choice of legal integer sizes that will cause it to do the wrong thing or cause undefined behavior. | |
Feb 19, 2015 at 18:36 | comment | added | Doval |
@MSalters Most people expect int to be 32 or 64 bits but it can be as small as 16 bits. It's not hard at all to produce a number outside the range of [−32767, +32767] and int overflow is UB. There's also char /short getting promoted to int or unsigned int depending on whether int can represent every value of the original type, which can further trigger a conversion from int to unsigned int if the operands had different types and got converted differently, plus potentially another conversion when you assign the result to a variable.
|
|
Feb 19, 2015 at 18:07 | comment | added | Random832 | @MSalters In reality, compiler writers for an established platform have the burden of matching what others that went before them did. Sometimes this is documented and standardized, sometimes not. It's easy to find what size an int is, but harder to find what is done with register values and where arguments are stored when calling a function (which may change depending on the argument types and return type of the function), struct layout rules, etc. | |
Feb 19, 2015 at 16:11 | comment | added | MSalters | How is int size " Undefined Behavior" ? And why would be UB be a burden on compiler vendors anyway? The only real burden for compiler writers is that int widths are implementation defined, not unspecified, so you have to document what you did. | |
Feb 19, 2015 at 6:31 | comment | added | Basile Starynkevitch | SML/NJ and PolyML are both compiling to machine code... | |
Feb 19, 2015 at 2:41 | history | answered | Telastyn | CC BY-SA 3.0 |