News for hackers. Stuff that matters.
Re:Why Zig When There Is Already CPP, D, and Rust? (2017) by RhysU on Sunday October 14, 2018 @09:03PM (#18216666)
Please do share.
Re:Why Zig When There Is Already CPP, D, and Rust? (2017) by thechao on Monday October 15, 2018 @01:36PM (#18221766)
As, below, there's a new statement: '_Generic()'. The expression looks like this:

    _Generic(x, type : value, ..., [default : value])
For a list of unique types, with an optional 'default' for any unrecognized type.

You usually wrap the call to '_Generic' in a macro. For instance:

    #define vec_push_back(vec, val) \
        _Generic(&vec, \
        vecint : vecint_push_back, \
        vecdbl : vecdbl_push_back, \
        default : assert_vwrap)(&vec, val)
Assuming that types 'vecint' and 'vecdbl' have been defined by the user. This does single-parameter parametric type dispatch. There's way to allow the user to use table-driven macros ('X-macros') to allow per-translation-unit definition of an arbitrary number of instantiations.

The nice part, over C++, is that the generic instantiation is localized to a single translation-unit file, so you don't have to yell at the junior devs for instantiating templates without using an 'extern' construct.

Re:Why Zig When There Is Already CPP, D, and Rust? (2017) by isaachier on Sunday October 14, 2018 @10:33PM (#18217043)
I imagine this is about tgmath.h. I've found the use of the word generic a bit misleading there.
Re:Why Zig When There Is Already CPP, D, and Rust? (2017) by cygx on Monday October 15, 2018 @01:41AM (#18217620)
No, it's very likely about _Generic. <tgmath.h> was added to C99 in an attempt to steal Fortran mindshare, ie making numerics and scientific computing less cumbersome (the same is true for other features, eg complex numbers or restrict). But in C99, it was still special-cased. The next standard C11 introduced _Generic so people could create their own type-generic interfaces.