🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9166

Re: macro to specify output parameter

#9166
From: Stuart D. Gathman
Date: Wed, 20 Aug 1986 05:05
56 lines
2795 bytes
In article <6229@sun.uucp>, guy@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.
Technical Details
Message-ID: <161@BMS-AT.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!vrdxhq!BMS-AT!stuart
References: <522@bunny.UUCP> <6229@sun.uucp>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!vrdxhq!BMS-AT!stuart
From: stuart@BMS-AT.UUCP (Stuart D. Gathman)
Newsgroups: net.lang.c
Subject: Re: macro to specify output parameter
Message-ID: <161@BMS-AT.UUCP>
Date: Wed, 20-Aug-86 01:05:08 EDT
Article-I.D.: BMS-AT.161
Posted: Wed Aug 20 01:05:08 1986
Date-Received: Thu, 21-Aug-86 01:53:59 EDT
References: <522@bunny.UUCP> <6229@sun.uucp>
Distribution: net
Organization: Business Management Systems, Inc., Fairfax, VA
Lines: 56
Summary: I don't like it.