Clarification on Free and Payed C standard specification - c

I found (in http://c-faq.com/ansi/avail.html) that "An electronic (PDF) copy is available on-line, for US$18, from www.ansi.org".
But at the same time, I can download it for free from http://www.open-std.org/JTC1/sc22/wg14/www/docs/n1256.pdf
Both are C standards, right ? What is the difference between two ?

The latter is a draft. Accurate and containing everything you need, but in draft form.
This is a WG14 working paper, but it reflects the consolidated
standard at the time of issue

All the documents like n1234 are draft versions of the standards. If you want the real, published versions, you have to buy them from your local standards organisation.
That's rarely necessary unless you're Microsoft, Borland/Unprized/Enchilada (or whatever they call themselves nowadays), IBM or some other compiler writer. Normal people get by quite adequately on the late-edition drafts just fine.

The latest draft, dubbed C1X, and approved for publication, is http://www.open-std.org/JTC1/sc22/wg14/www/docs/n1548.pdf. This is probably as close to the next standard as you will be able to get without paying for the formalized version.
Better to take that version, since n1256 missed several clarifications and corrections.

Related

Compatibility of C89/C90, C99 and C11

I just read: C Wikipedia entry. As far as I know there are 3 different versions of C that are widely used: C89, C99 and C11. My question concerns the compatibility of source code of different versions.
Suppose I am going to write a program (in C11 since it is the latest version) and import a library written in C89. Are these two versions going to work together properly when compiling all files according to the C11 specification?
Question 1:
Are the newer versions of C i.e. C99, C11 supersets of older C versions? By superset I mean, that old code will compile without errors and the same meaning when compiled according to newer C specifications.
I just read, that the // has different meanings in C89 and C99. Apart from this feature, are C99 and C11 supersets of C89?
If the answer to Question 1 is no, then I got another 2 questions.
How to 'port' old code to the new versions? Is there a document which explains this procedure?
Is it better to use C89 or C99 or C11?
Thanks for your help in advance.
EDIT: changed ISO C to C89.
Are the newer versions of C i.e. C99, C11 supersets of older C versions?
There are many differences, big and subtle both. Most changes were adding of new features and libraries. C99 and C11 are not supersets of C90, although there was a great deal of effort made to ensure backwards-compatibility. C11 is however mostly a superset of C99.
Still older code could break when porting from C90, in case the code was written poorly. Particularly various forms of "implicit int" and implicit function declarations were banned from the language with C99. C11 banned the gets function.
A complete list of changes can be found in the C11 draft page 13 of the pdf, where "the third edition" refers to C11 and "the second edition" refers to C99.
How to 'port' old code to the new versions? Is there a document which explains this procedure?
I'm not aware about any such document. If you have good code, porting is easy. If you have rotten code, porting will be painful. As for the actual porting procedure, it will be easy if you know the basics of C99 and C11, so the best bet is to find a reliable source of learning which addresses C99/C11.
Porting from C99 to C11 should be effortless.
Is it better to use C89 or C99 or C11?
It is best to use C11 as that is the current standard. C99 and C11 both contained various "language bug fixes" and introduced new, useful features.
In most ways, the later versions are supersets of earlier versions. While C89 code which tries to use restrict as an identifier will be broken by C99's addition of a reserved word with the same spelling, and while there are some situations in which code which is contrived to exploit some corner cases with a parser will be treated differently in the two languages, most of those are unlikely to be important.
A more important issue, however, has to do with memory aliasing. C89 include
rules which restrict the types of pointers that can be used to access certain
objects. Since the rules would have made functions like malloc() useless if
they applied, as written, to the objects created thereby, most programmers and
compiler writers alike treated the rules as applying only in limited cases (I doubt C89 would have been widely accepted if people didn't believe the rules applied only narrowly). C99 claimed to "clarify" the rules, but its new rules are much more expansive in effect than contemporaneous interpretations of the old ones, breaking a lot of code that would have had defined behavior under those common interpretations of C89, and even some code which would have been unambiguously defined under C89 has no practical C99 equivalent.
In C89, for example, memcpy could be used to copy the bit pattern associated with an object of any type to an object of any other type with the same size, in any cases where that bit pattern would represent a valid value in the destination type. C99 added language which allows compilers to behave in arbitrary fashion if memcpy is used to copy an object of some type T to storage with no declared type (e.g. storage returned from malloc), and that storage is then read as object of a type that isn't alias-compatible with T--even if the bit pattern of the original object would have a valid meaning in the new type. Further, the rules that apply to memcpy also apply in cases where an object is copied as an array of character type--without clarifying exactly what that means--so it's not clear exactly what code would need to do to achieve behavior matching the C89 memcpy.
On many compilers such issues can be resolved by adding a -fno-strict-aliasing option to the command line. Note that specifying C89 mode may not be sufficient, since compilers writers often use the same memory semantics regardless of which standard they're supposed to be implementing.
The newer versions of C are definitely not strict super-sets of the older versions.
Generally speaking, this sort of problem only arises when upgrading the compiler or switching compiler vendors. You must plan for a lot of minor touches of the code to deal with this event. A lot of the time, the new compiler will catch issues that were left undiagnosed by the old compiler, in addition to minor incompatibilities that may have occurred by enforcing the newer C standard.
If it is possible to determine, the best standard to use is the one that the compiler supports the best.
The C11 wikipedia article has a lengthy description of how it differs from C99.
In general, newer versions of the standard are backward compatible.
If not, you can compile different .c files to different .o files, using different standards, and link them together. That does work.
Generally you should use the newest standard available for new code and, if it's easy, fix code that the new standard does break instead of using the hacky solution above.
EDIT: Unless you're dealing with potentially undefined behavior.

Are there any plans for a future C standard after C11?

I searched on the open standards website, particularly the C working group homepage but only found information about C11.
They seem to have regular meetings and discuss different features and extensions, but they never actually mention a future C standard nor roadmap. It is hard to tell whether they are working on a new standard or just a Technical Corrigendum to the current standard.
I sent an email to the guy on the WG 14 contact section but I didn't expect to get an answer anytime soon, however, I did.
This is what he replied to me:
the Committee has not discussed starting work on a new revision of the
Standard. WG 14 will be meeting in Parma Italy the first part of
April, and so far there as not been any proposals for new features
that would prompt the revision process.
Thanks,
John Benito - ISO/IEC JTC 1/SC 22/WG 14 Convener
So I guess this is as official as it gets for now.
It appears there is discussion about the next C standard, C2x, and there are proposals as well.
You can view the charter here.
And, you can view the email list here.
At the bottom of the charter, it indicates an expected publication date of 2022.
There is C18 (https://www.iso.org/standard/74528.html) standard released in June 2018 but it only addressed flaws in C11 without introducing new language features.
A technical corrigendum is issued to correct a technical error or ambiguity. New features and extensions need to be published as an amendment or revision of the standard.
See here for an in depth description of the procedure for developing an international standard:
http://isotc.iso.org/livelink/livelink?func=ll&objId=4230452&objAction=browse&sort=subtype

Where would I go with an idea for the next C standard?

I've been reading up a lot on how C works, and I think I have an idea for how to make it better. From what I've read it seems like the standard changes from time to time, and I was wondering if there is a place I could go to submit a new idea for the next revision.
The committee's web site is http://www.open-std.org/JTC1/SC22/WG14/.
Their contact info is at http://www.open-std.org/JTC1/SC22/WG14/www/contacts.
The most recent C standard was released late last year; a draft that should be almost identical to the released standard, is N1570, or you can buy the official standard from the ANSI store, or from your national standards body.
Ideas are often discussed on the comp.std.c Usenet newsgroup; it's a good place to get feedback, but it has no official association with the committee.
Your idea will have a much better chance of being adopted if you can demonstrate existing practice, i.e., and existing C compiler that already implements it as an extension -- and if it doesn't violate the vaguely defined "spirit of C".

Documents about C language specs

I'm wondering about the difference between what is defined by the several standards of the C language and the things that every compilers implements in a different way from the others, i want to really understand what the official specs of the C language are: there are some official docs?
I'm looking for technical stuff, not a thread on the internet, some good pdfs maybe; something that can describe everything happens with the memory management, the allocation, the lenght and the encoding of the variables, etc etc ...
I have the official manual from K&R but it's not really about what i am interested to, it's more on the "programmer side" i want something more technical and affermative.
PS
the C language have an official website for reference?
Check this
"Obtaining the Standard
Neither the Standard nor its amendments are available free of charge, although its drafts, rationales, technical corrigenda (TCs) and defect report responses are.
The Standard can be purchased in hardcopy and/or downloadable digital format from national affiliates as described on the WG14 website. Two such national bodies are ANSI - through its eStandards Store - and SAI Global (originally Standards Australia) which sells all of the ISO C Standard publications. One international source is Techstreet.
Listed below are direct links to pages for purchase or free download of the Standard, its TCs, amendments, drafts, rationales and defect report responses for each version of the Standard. The set of documents is comprehensive whereas the list of sources obviously is not."
Tried to add this as a comment but the URL would not take.
Try: http://www.deitel.com/Default.aspx?tabid=204 for details on C. I also suggest you dig up GNU's big document on C as they do some things differently and it can be important to understand GNUs way of doing things. http://gcc.gnu.org/onlinedocs/.

Is there a new upcoming C Standard that supersedes C99?

Is there a new upcoming C Standard that supersedes C99? After all there's an unofficial C++0x coming out as per the source in Wikipedia here. For the sake of this question, let's call this C99 superset as C'y2k.01' to not confuse (as I was going to say C99++ which looks like the C++ counterpart.... but I digress)
If there isn't, what would you like to see in the C'y2k.01' standard today in order for the C language to survive in the 21st century? Sure there's Java, .NET, C#, Scala, Erlang, F# to name but a few, but really, go on...
I would like to see:
Unifying the Posix functions into the runtime,
with the #1 mentioned above, fork()ing would be much easier and parallelizing the code would be made possible instead of relying on a third party library
The ease of dynamic memory for custom collections such as arrays ... something like this 'char __dynamic foo[];' where you can add/remove elements easily
This is open to debate and discussion.
Thanks.
There is a project in place to update C99. The draft is currently dubbed C1X and is available here. You can also see the charter.
You can see a list of the currently open projects and get up to date news from the ISO C Working Group.

Resources