macro to specify output parameter
Stuart D. Gathman
stuart at BMS-AT.UUCP
Wed Aug 20 15:05:08 AEST 1986
In article <6229 at sun.uucp>, guy at sun.uucp (Guy Harris) writes:
> This may, in fact, also be an argument for reference types a la C++; there,
> your routine "foo" would be written as
>
> foo(c)
> char &c;
> {
> ...
> c = 'a'; /* store 'a' in the "char" referred to by
> "c" */
> ...
> }
I don't like this. It violates the nice consistent way that C expressions
work. 'char *c' means that '*c' is of type char. '&c' is not of type
char in any other context. I don't see any problem with using '*' instead
of REF and DEREF. In any case, either '*' or 'DEREF' is better than
the foo example above since the uses of the output parameter are marked.
This is certainly an argument for DEREF over '*', but I still think
'*' looks prettier (but then I love APL).
I would like to see variable size arrays allowed as local parameters.
This would be a lot more efficient than using malloc().
I would like to "operator definition" which would allow you to opdef
say '+' to cause it and its two arguments to be replaced by a macro
called with the two arguments whenever the arguments are of a type
specified in the definition. This allows generalized treatment of
operators on non-native types such as 'complex'. Perhaps new operators
could be custom defined or the syntax (left/right association, priority)
of existing operators changed (but probably not except for completeness,
changing existing operators is a good way to make a program unreadable).
I would like to see "structure constants" which would allow assignment
to aggregate types.
typedef struct { double real, imag; } complex;
complex z;
int a;
a = 0;
z = { 0, 0 };
. . .
z = { a+1, exp(b) };
foo( (complex) { a, b } );
Of course any of these could be coded by assigning each member in turn.
I just think the above is nicer and not hard to implement.
Macros would be nicer with "imbedded functions".
#define foo(x,y) { float a = 0.0; while (x) { a += y * x--; }; return a; }
This construct is distinguished by the use of '{}' in a context
requiring a value. The return is optional, the value of the last
expression is used. Perhaps loops should be allowed in comma expressions
instead.
More information about the Comp.lang.c
mailing list