4 ms·
I don't know the reasons for why so many things are undefined in C. However, if a program does one thing when compiled with compiler A and another thing when c
by tmalsburg2 11y ago
I don't know the reasons for why so many things are undefined in C. However, if a program does one thing when compiled with compiler A and another thing when compiled with compiler B, how does that help portability? To my perhaps naive mind this makes portability harder to achieve not easier.
- pjc50 11y agoA classic example of trying to define behaviour regardless of what all the different hardware does is Java choosing IEEE754 floating point. Which isn't natively supported on x86. https://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf https://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf If C had standardised to the idiosyncracies of the PDP-11, it might have held back its development.
- jey 11y agoAre you referring to 80-bit floats used by the (long obsolete) x87 FPUs?
- pjc50 11y agoThe 80-bit floats were still in use right through the 2000s; I know because I had to work out what option to use to get reproducible fp rounding on 64-bit doubles in 32-bit C. I've not had occasion to look at the details of amd64 fp.
- edmccard 11y ago>Java choosing IEEE754 floating point. Which isn't natively supported on x86. IEEE754 was based on the design of the 8087, and it's been native on x86 since the 80387. The problem with Java choosing IEEE754 was, according to the paper you linked, not that it wasn't supported on all hardware, but that Java didn't follow the spec completely, "Later we shall see why Java’s expanded market would be served better by actual conformity to the letter and spirit of IEEE Standard 754"
- habitue 11y agoThe point is you are supposed to avoid undefined behavior, precisely because these things can be different between compilers. In theory, this lets the compilers optimize better for a specific platform/cpu, while avoiding changing the meaning of the programmer's code. In practice, most platforms and compilers have done the same exact thing with the same "undefined" behavior, that a large body of code relies on that defacto standard.
- mcguire 11y ago"In practice, most platforms and compilers have done the same exact thing with the same "undefined" behavior, that a large body of code relies on that defacto standard." All compilers on the same platform have done the same exact thing with the same "undefined" behavior. At the moment, all platforms are x86. Previously, all platforms were SPARC, and before that, VAX.