Gisle Vanem wrote: > > +#define generic_math_op(a, b, op) > > \ > > + ((void)sizeof ( > > \ > > + char[__builtin_types_compatible_p (typeof (a), typeof (b)) ? 1 : > > -1]), \ > > + _Generic ((a), > > \ > > + double: generic_math_op_double, > > \ > > + long long int: generic_math_op_ll) (a, b, op))
> this is some GNU-C-ism that wont compile with MSVC. I will remove the use of __builtin_types_compatible_p > > +static char * > > +func_add (char *o, char **argv, const char *funcname) > > +{ > > + struct number n = perform_math_op ( > > + op_add, funcname, > > + (struct math_operation_init){ .init_type = t_constant, .constant = 0 > > }, > > + argv); > Not sure about such inline 'structs'. These are called "compound literals" and have been part of C since C99. More broadly though, what is the newest version of C that I may rely on? The use of "_Generic" is a C11 thing. I can remove it if we want to rely only on C99. Should I write some unit or integration tests? On Fri, Nov 29, 2024 at 7:34 AM Gisle Vanem <gva...@yahoo.no> wrote: > > Pete Dietl wrote: > > > Here I submit to you a patch that adds the following builtin functions > > to make: `add` (addition), `sub` (subtraction), `mul` > > (multiplication), `div` (division), `mod` (modulus), `max` (maximum), > > `min` (minimum), and `abs` (absolute value). The implementation I > > provide supports both integers and floats with promotions from integer > > to float when appropriate (an operation where at least one argument is > > a float causes the other argument to be promoted to a float and the > > result to be a float). > > This would be nice, but... > > > +#define generic_math_op(a, b, op) > > \ > > + ((void)sizeof ( > > \ > > + char[__builtin_types_compatible_p (typeof (a), typeof (b)) ? 1 : > > -1]), \ > > + _Generic ((a), > > \ > > + double: generic_math_op_double, > > \ > > + long long int: generic_math_op_ll) (a, b, op)) > > this is some GNU-C-ism that wont compile with MSVC. > > > +static char * > > +func_add (char *o, char **argv, const char *funcname) > > +{ > > + struct number n = perform_math_op ( > > + op_add, funcname, > > + (struct math_operation_init){ .init_type = t_constant, .constant = 0 > > }, > > + argv); > > Not sure about such inline 'structs'. > > -- > --gv >