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