Malcolm McLean said:You can't use strings for speed-critical code, agreed.
C programmers do expect runtime micro-efficiency. But you're already being
idiomatic by introducing named arguments.
Is it being non-ideomatic or is it just using varargs (which could be called
idiomatic due to heavy usage in printf-family function calls) sensibly? Or
is it non-ideomatic for using varargs in an unusual way?
Normal uses of varargs (if they could be called normal) use one parameter to
control what the rest do. For example, sprintf has the form
sprintf(stream, string, ...)
In this case the string defines the number and types of arguments expected.
But if we wanted a call similar to malloc to which we could pass some other
parameters it might be better to use
In this case the parameters could appear as pairs of (attribute_id, value)
followed by a final pseudo attribute id of zero. So the basic call without
any extra parms would be
A call to allocate memory below a certain address might be
mem_alloc(size, MEM_BELOW, addr_limit, 0);
where MEM_BELOW is the parm id integer used by the mem_* routines.
That's largely bad.
You can just use "x" or "N" as a string. With integers and bit masks, it's
got to be
Yes, the lengths of the names and, in particular, their prefix, would be an
issue due to C's lack of namespace support. (One of the few things that
can't be fixed by low-level programming as it's a limitation of the
That's a slight advantage. You can't pass "X" or "x " accidentally. But
mostly those bugs
are easily caught when you parse the name / argument pairs.
Well, YMMV but to me that's a big advantage.