if you want to mimic C++ "assumed" arguments behavior you can do something like below...
Let's say we have a function that calculates the length of a 4 dimensions vector (x,y,z,w). But I want to pass only a 3d vector, assuming w=1:
Code:
// vector structure
typedef struct { double x, y, z, w; } vec4_T;
// macro, assumed .w=1.
#define vec4_length(...) \
vec4_length_( ( vec4_T ){ .w = 1.0, __VA_ARGS__ } )
double vec4_length_( vec4_T v )
{
if ( v.w != 0.0 && v.w != 1.0 )
{
v.x /= v.w;
v.y /= v.w;
v.z /= v.w;
v.w = 1.0;
}
return sqrt( v.x * v.x + v.y * v.y + v.z * v.z );
}
// calling examples
double l = vec4_length( .x=1, .y=1, .z=3 );
double m = vec4_length( .x=1, .y=1, .z=1, .w=3 );
If no designator is given, (x,y,z) will be 0... This is not a perfect mimic.
Notice: ISO 9989 (C99 & C11) says (6.7.8 - about initializers) this is ok.