Variable-Length Array Parameters in NCEG C

Peter S. Shenkin uunet!avogadro.barnard.columbia.edu!shenkin
Sun Jul 5 16:35:58 PDT 1992


> But what happens in a case like 
> 
> 	static int n=3;
> 
> 	void a(float b[n], int n)
> 
> Having no Fortran analog, this doesn't arise in simple translations into C,

Wouldn't the following constitute a Fortran analog:

	SUBROUTINE a( b, n )
	COMMON/com1/n
	REAL b( n )

My copies of the relevant references are packed up right now, but I believe
that this is illegal Fortran.  On the other hand, it would be more C-like
for the local reference to override the static one, regardless of order
of declaration.

> Nor does [allowing n to be used before it is declared in a prototype]
> fit with the way C declarations usually work.
> Stallman's view is that grafting order-independent declarations of this sort
> onto GCC would be so ugly that nobody would do it on GCC.   I wonder if this
> might be true generally for other compilers.
> 
> So my question for mathematical software providers is:  how important is this
> kind of order independence for hand-translating Fortran code to C?...

I think it is at least equally important to ask: How important is this
kind of order independence for writing new scientific code in C?  

My opinion is that it would be best from the point of view of the C user 
if the compiler writers would do the work once, regardless of their 
aesthetic views, and free the language users from having to deal with 
this annoyance with with every program they write.

But if, for whatever reason, the compiler writers are not willing to bite 
this particular bullet, the "compromise" proposals presented at
least have the advantage that the writer of new C code would have to
worry about this issue only when writing the function definition and
prototype, and would be free to order the arguments arbitrarily, with
no special syntax, in a function call.  Thus the provider of a 
library would have to worry about this issue, but the users of the 
library would not.  This is a Good Thing, as far as it goes, but again, 
speaking as a C user, I would still like to see it to go further.

	-P.
************************f*u*cn*rd*ths*u*cn*gt*a*gd*jb*************************
Peter S. Shenkin, Department of Chemistry, Barnard College, New York, NY 10027
(212)854-1418    shenkinaavogadro.barnard.columbia.edu   shenkinacunixf.BITNET
******************** The singular of "media" is "medium". ********************




More information about the Numeric-interest mailing list