13 ms·
Here are major C11 Standard changes: - standard multithreading support (<threads.h> header) - atomic operations (<stdatomic.h> header) - type-generic mac
by kia 15y ago
Here 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.
- deleted 15y ago[deleted]
- kzrdude 15y agoIt should be just O_EXCL, which is POSIX.
- Someone 15y agoThe draft specifies that this should work "to the extent that the underlying system supports exclusive accesss", so basically, you are hosed if you use this :-) On some systems, this will mean no locking, on others, advisory locks, on yet others, no locking at all. I bet it will depend on the file system, too (NFS mounts, I am looking at you)
- markokocic 15y agoStandard threading finally. Now, when this get traction, it will be much easier to port non trivial applications between various operating systems.
- DavidSTO 15y agoC95* + POSIX Imagine if da Vinci couldn't stop himself from painting the Mona Lisa and decided to add a little of her endearing facial hair there under the lip. * C89 + Amendment 1 (and, as usual, try really hard to stay out of the way of the Sasquatch sized footprints being added by the "new and improved standards.")