Xref: utzoo comp.lang.fortran:824 comp.lang.c:10965
Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!agate!ig!uwmcsd1!vanvleck!uwvax!oddjob!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.lang.fortran,comp.lang.c
Subject: Re: Should I convert FORTRAN code to C?
Keywords: language conversions, FORTRAN, c
Message-ID: <12184@mimsy.UUCP>
Date: 28 Jun 88 10:31:29 GMT
References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <1190@mcgill-vision.UUCP>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 35

>In article <738@naucse.UUCP> rrr@naucse.UUCP (Bob Rose) suggests that
this C code is is legal:
>> 	double a[2][5]        /* <-- note [2][5] not [5][2] */
>> 	....foo(a)....
>> 	void foo(double a[10]) { ... }

In article <1190@mcgill-vision.UUCP> mouse@mcgill-vision.UUCP (der Mouse)
gets the right answer, and the right reason:
>No, I'm afraid not.  foo() is expecting an array of ten doubles.
>Instead, you're passing it ... Actually, a pointer to an array of
>five doubles.)

but the wrong explanation:
>What's the difference?  To put it briefly, I find no guarantee that
>sizeof(double[5]) == 5*sizeof(double).

There is indeed such a guarantee.  The one that is missing, which makes
this particular example fail, is that pointers to arrays of objects need
not at all resemble pointers to the objects themselves.

Please remember that C is a strongly typed language (no matter what
else you have been told).  Mixing types is often legal, and the
cross-checking required by the language is extremly weak, but the
type system itself is quite strong.  The difference is like that
between an extensive law system and extensive enforcement:  If the
system is there, any missing enforcement can be provided later, at
need, without much hassle.

The whole example may be corrected quite simply:

	... foo(&a[0][0]); /* or foo(a[0]) */ ...

	void foo(double a[10]) /* or void foo(double *a) */ { ... }
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris