|
|
Subscribe / Log in / New account

Obsolete C for you and me

Obsolete C for you and me

Posted Dec 10, 2023 19:49 UTC (Sun) by smoogen (subscriber, #97)
In reply to: Obsolete C for you and me by NYKevin
Parent article: Modern C for Fedora (and the world)

I remember dealing with some code in I had written to meet K&R Second edition which was based on the ANSI C (so around 1990?) but would not compile on some Sun or HP boxes. My mentor asked me if I had run the linter which spewed out various complaints. Using the older version and removing various 'sugar' to match the 77 C, the code compiled and ran. So my guess is that between 77(?) and 90, the original K&R was considered the implementation standard. [Because this turned into a regular problem, I ended up having both editions of K&R to remind myself what I might need to do with older code.]


to post comments

Obsolete C for you and me

Posted Dec 10, 2023 20:36 UTC (Sun) by NYKevin (subscriber, #129325) [Link] (1 responses)

Sure, that is a valid thing you might have to do as a user.

What I'm really getting at is, what is K&R C, from the compiler author's perspective? How do you know if a given compiler is a "valid" implementation of K&R? How do you know what optimizations are permitted? If the answer is "no optimizations are allowed, because there's no C abstract machine yet, so everything must be translated 1:1," then how do you decide what constitutes "1:1" output? Even the modern C standard does not define such a notion, and users would probably like to have some optimizations anyway.

I don't think there's any sensible answer to those questions that doesn't ultimately look like C89 with a bunch of -f options to enable K&R constructs, which is why there's no -std=kr option. The second edition explicitly acknowledges this limitation in the preface, and directs compiler authors to the C standard.

Obsolete C for you and me

Posted Dec 11, 2023 16:03 UTC (Mon) by smoogen (subscriber, #97) [Link]

Ah ok. I see what you meant. [My only guess would be that the standard before 89 would have been the AT&T compiler for Unix's before then (aka it was written by the Gods and so it is what we must follow.] That however probably also leads to every compiler before then having 'well it only really works this way on that CPU and OS.. we need it to do this on this arch.'


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds