6 ms·
ISO updates C Standard (Now we have C11)
- xxiao 15y agonice. would like to find out all the new stuff in some blog/books before I had to read the standard itself, plus the status of toolchain supports of them(gcc seems only support part of the new standard)
- Kliment 15y agoYou have to pay money to even look at it. That makes supporting things difficult.
- bchjam 15y agoat least you can read the draft http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
- nknight 15y agoANSI will have relatively inexpensive PDFs soonish. There won't be any trouble getting copies to the people that most need it. [This should not be construed as a defense of the rather insane practice of charging for these standards in the first place.]
- _exec 15y agoAnother HN user posted this link on TPB: http://thepiratebay.org/torrent/6670023/Official_Standard_C__0x_C__11_CPP_CXX_ISO_IEC_14882_2011 http://thepiratebay.org/torrent/6670023/Official_Standard_C_...
- kzrdude 15y agoThat's C++11, a different language.
- kia 15y agoHere are major C11 Standard changes: - standard multithreading support (<threads.h> header) - atomic operations (<stdatomic.h> header) - type-generic macros (sqrt translates to sqrt, sqrtf, sqrtl depending on argument type) - Unicode support (char16_t and char32_t types) - gets function is removed from the standard (use gets_s) - static assertions - aligned memory allocation (aligned_alloc) - anonymous structures and unions - no-return functions (specify functions that never return) - exclusive access for opened files ("x" in fopen) - macros to create complex numbers - additional way to terminate the program (quick_exit and at_quick_exit)
- slavak 15y agoI was curious how type-generic macros can be implemented in C, so I looked up an explanation of how it's done in glibc. It's quite fascinating (despite being an unholy abomination): http://carolina.mff.cuni.cz/~trmac/blog/2005/the-ugliest-c-feature-tgmathh/ http://carolina.mff.cuni.cz/~trmac/blog/2005/the-ugliest-c-f...
- radarsat1 15y ago> exclusive access for opened files ("x" in fopen) Wouldn't this need to be a service provided by the operating system? How can it be part of the standard? Or is it just that the standard prescribes that "x" must work if the operating system allows it. I know Windows usually defaults to exclusive access, but in practice do any unix-like systems provide exclusive access for file read? Just wondering since I've never requested exclusive read access in my Linux programming.
- jlarocco 15y agoYeah, it requires OS support, but it's no different than most of the standard library. Opening files, writing to files, printing to the console, allocating memory, etc. all require OS support, too. As to how it can be implemented, "man 2 open" on OSX shows O_EXLOCK and O_SHLOCK flags, and they're from BSD. Not sure if they're POSIX, but I'd bet Linux has something equivalent. And there's also the flock() function. My guess is the new "x" option to fopen can be implemented using O_EXLOCK and flock(), though I'm too tired to look up details on how it could be done.
- wnoise 15y agoAnd they still haven't adopted the C++ const-correctness rules (for pointers to pointers to ...), which really do help in writing correct code, and correct code that has flavor of C89.
- erydo 15y agoWhat? C has those const rules. The type "int const* const*" is valid C. The differences are primarily that in C you can't use a const symbol in a place where a constant expression is expected (e.g. initializing another const, or a statically sized array). But you can absolutely do const-correct code in C.
- kzrdude 15y agoThe issue is laid out here by C-FAQ: http://c-faq.com/ansi/constmismatch.html http://c-faq.com/ansi/constmismatch.html
- wnoise 15y agoIt has a set of const-correctness rules. They're much simpler than the C++ rules. While they handle the simple cases perfectly well, they forbid some assignments that really can't get you in trouble, and would be quite useful in practice. In particular, while "int const * const * " exists, it can't be assigned from an "int * * ", even though this is sound. This makes it hard to write const-correct functions handling 2-d arrays.[1] kzrdude's link shows how they have to rule out certain constructs that are not obviously wrong. It doesn't explain how the C++ assignment compatibility rules allow more, while still being sound, but that's a bit much to expect from a C FAQ, particularly as the C++ rules are somewhat involved. (I can't find a decent reference that explains the rules well. I found one about six months ago, but didn't save it, as I don't professionally use C++.) [1]: Preemptive pedanticism: Yes, there are difference between C arrays and pointers, the expression types merely decay in the right contexts. But if I'm using [] to dereference, they're being used as arrays.
- frou_dh 15y agoFor personal projects, I'm going to try and use ANSI C89 forever. I know this isnt especially rational but it's somehow appealing to stick with a small(er) and more historic version.
- haberman 15y agoI think that <stdint.h> is a C99 feature worth using -- otherwise each project has to redefine eg. myuint32_t over and over again. Colossal waste of effort and namespace pollution.
- TheNewAndy 15y agoMost of the time you don't actually care about the exact size of your integer types (especially for signed integers). At work, we use C90 with a few C99 extensions which can be disabled through the preprocessor (e.g. inline, restrict) and although we stared out with a stdint.h like thing, it is proving to be less useful.
- frou_dh 15y agoDefinitely. That's comfort for the existence of "long long"!
- endgame 15y agoThat's your call and I admire it (I think that restriction is a major cause of Lua's famous portability). I like the C99 struct initialisers and the ability to declare things right next to their use site too much to go back.
- ysangkok 15y agoGood luck in convincing anyone that doing something that's not rational is a good idea. The very definition of rationality is something that represents something good and necessary. I don't know why you'd try and argue for non-rationality/mysterious/spiritual reasons when using something is mathematical and scientific as computers. It's a bad combination. Also, you don't have to use the whole standard. You know there are people who use C++ for hobby projects? That standard is dozens of times larger than the C standard.
- Apocryphon 15y agoI'm still disappointed that K&R never released a third edition.
- deleted 15y ago[deleted]