News for hackers. Stuff that matters.
Re:Maximal Min() and Max() by spc476 on Thursday August 08, 2024 @09:44PM (#41198125)
At this point, C and C++ are not compatible. Please stop with this "Oh, just compile C with a C++ compiler." That ship has sailed over twenty years ago with C99. One major difference is designated initializers, which works differently between C and C++ [1]. And C also allows structure literals in function calls:

    cgci = XCreateGC(
             display,
             window,
             GCForeground | GCBackground | GCFont,
             &(XGCValues) {
               .foreground = ccwhite,
               .background = ccblack,
               .font       = cfont->fid,
             }
           );
[1] C++ requires the fields to be initialized in order; C doesn't have this restriction.
Re:Maximal Min() and Max() by wahern on Friday August 09, 2024 @12:28AM (#41198766)
Compound literals are especially pernicious[1] because GCC and (I think) clang support them in C++ mode, but they have expression lifetime like C++ temporary objects, not block lifetime as in C. That's a guaranteed recipe for dangling pointers and stack smashing/snooping.

[1] From a C++ is just a C superset perspective. In C compound literals are awesome.