Re:What is your favorite C programming trick? (2009)
by flohofwoe on Sunday November 22, 2020 @01:27PM
(#25179667)
There's a surprising amount of perfectly valid C code that's not valid C++ (not even taking regrettable design warts like VLAs into account). The "common subset" of C and C++ is both a subset of C, and a subset of C++, e.g. C++ has forked C and turned its C subset into a non-standard dialect.
It's interesting that the other C descendant Objective-C has decided to "respect" its C subset instead of messing with it, with the result that new C standards are automatically supported in ObjC.
Re:What is your favorite C programming trick? (2009)
by pjmlp on Sunday November 22, 2020 @02:22PM
(#25180200)
A descendant that would be dead by now wouldn't Apple decided to buy NeXT.
VLAs are dead, a broken design fixed in C11 by removing it from the standard, no idea why everyone keeps referring to them.
Re:What is your favorite C programming trick? (2009)
by yakubin on Sunday November 22, 2020 @12:47PM
(#25179354)
> A subset of designated initializers is supported in C++20.
Took them only 21 years... And this standard being so recent, most projects won't have that for years to come.
Re:What is your favorite C programming trick? (2009)
by pjmlp on Sunday November 22, 2020 @01:13PM
(#25179546)
Doesn't matter, the point was what C subset does C++ support today.
Re:What is your favorite C programming trick? (2009)
by vitus on Sunday November 22, 2020 @06:22PM
(#25182043)
C++20 designated initializers must be specified in definition order, whereas they don't in C99.
In your example,
Point point = {.z = 2.0, .x = 1.0};
produces a compilation error. This is annoying, but workable. And at least it's a compile-time error, rather than a bug that perniciously sneaks into production.
Re:What is your favorite C programming trick? (2009)
by pjmlp on Monday November 23, 2020 @02:03AM
(#25184236)
Why do you think I wrote "A subset of designated initializers is supported in C++20."?
Re:What is your favorite C programming trick? (2009)
by saagarjha on Monday November 23, 2020 @03:48AM
(#25184795)
The one good use of VLAs I know of is casting a buffer into a multidimensional (variable-length) array to allow for subscripting to work.
Re:What is your favorite C programming trick? (2009)
by pjmlp on Monday November 23, 2020 @04:00AM
(#25184858)
Whatever good uses VLAs might actually have had, they are gone with C11.
Google even sponsored a massive effort to clean the Linux kernel of their use.
A subset of designated initializers is supported in C++20.