5 ms·
> Personally I'd rather see real-world extensions from gcc and clang moved into the standard which are already battle proven instead of wasting time fixing 30 y
by jcelerier 6y ago
> Personally I'd rather see real-world extensions from gcc and clang moved into the standard which are already battle proven instead of wasting time fixing 30 year old problems.
there's nothing that prevents you from using clang on all platforms, which will be exactly the same experience that if you used $LANG_WITHOUT_AN_ISO_STANDARD
- flohofwoe 6y agoOh but there is :) As a library author I really don't want to dictate users what compiler to use, they should at least be free to choose between the "big 3": gcc, clang and MSVC. Having those 3 compilers agree on more language features would be very helpful (this doesn't even need to happen through the standard, it would be enough if gcc, clang and MSVC would agree on a handful of important non-standard extensions).
- enriquto 6y agoicc is arguably bigger than msvc (which is not even a modern C compiler)
- saagarjha 6y agoThankfully, it will be soon: https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-...
- enriquto 6y agohmmmm, no complex numbers, no vla... not really what many people call modern C nowadays.
- saagarjha 6y agoDo people actually use those?
- kevin_thibedeau 6y agoVLAs are a bad idea and nobody doing modern C should be touching them. It's alloca() magic and introduces all sorts of stack destroying risk.
- ChickeNES 6y agoIsn't there a plan to remove them in the next C standard?
- pjmlp 6y agoAlready done in C11, they were marked optional, so any compiler that jumped from C89 to C11 (we are on the edge of C2x now), isn't required to even bother themselves with VLAs and will still achieve C11 certification (C17, C2X,...)
- enriquto 6y agoPutting VLA in the stack is just an implementation choice. A conforming implementation could allocate all VLA in the heap (and freeing the memory upon scope loss), or do not even use a stack/heap system at all. In that sense, VLA are a crucial language feature to allow a RAII-style for C code. Essentially, you could replace this void f(int n, ...) { float *t = malloc(n * sizeof*t); // do stuff with t[i] free (t); } with the following semantically equivalent code void f(int n, ...) { float t[n]; // do stuff with t[i] } Today, this is not a good idea for large arrays because, unfortunately, many C implementations put VLA in the stack. I hope that by keeping VLA in the standard language, future C implementations will get to favor this usage. Notice that VLA are not more dangerous or risky than recursion. The exact same argument that you use against VLA can be used against recursion. Are you against recursive functions in C? Of course, you wouldn't traverse a long array using recursion, but if you are careful that the depth of recursion is logarithmic with the array size (e.g. as in binary search), then it is perfectly safe and reasonable to use recursion. The same thing with VLA. If you are sure that n is 2,3 or at most 4 there's no reason to avoid VLA due to stack scare, and they may make your code much simpler, clearer and better. On the other hand, VLA are useful even if you do not use them to allocate memory. Pointers to vla can be used for many things, for example accessing a one-dimensional array (allocated by a single call to malloc) using two indices as if it was a 2d array.
- pjmlp 6y agoGiven that they were removed from the standard, yes modern.
- TwoBit 6y agoWhat do you mean by icc being bigger?
- enriquto 6y agoit's an answer to the parent's claim that the "big" three compilers are gcc, clang and msvc. I guess they meant that in the sense of "the most relevant", or "the most used". While microsoft's is unarguably an important C++ compiler, it's rarely used for non-legacy C code.
- pjmlp 6y agoBecause C++ compilers aren't required to be C compilers as well. However they have backtracked on their position regarding supporting C on Windows, so latest MVSC does support C11 and C17.
- jcelerier 6y ago> Oh but there is :) As a library author I really don't want to dictate users what compiler to use, sure, there's nothing wrong with self-inflicted pain. Rust shows that a compiler monoculture works much better in practice.
- pjmlp 6y agoWhen everything you need is Linux.
- jcelerier 6y agoI use a clang/libc++ toolchain to target Linux, macOS and Windows - works like a charm. It's also the toolchain used by Android and iOS, and I could also do some WASM with it. So portability here is definitely not an issue to me
- pjmlp 6y agoA small portion of operating systems and CPUs available in the market. I thought the message was about everyone not your bubble.
- jcelerier 6y agoc'mon, clang is able to target x86&64, ARM, AArch64, MIPS, AVR, RISC-V, WASM among others - those combined are 99.9% of the market (and 100% of the market for desktop apps).
- pjmlp 6y agoAmong others is still a smaller pie than either GCC or vendor specific compilers on embedded systems CPUs and operating systems.
- pjmlp 6y agoOther than the little fact that there isn't clang on all platforms, nor everyone supports it properly on their platforms even when available.