Article View: comp.sys.mac
Article #23633Re: LightSpeed C gripes
From: Oliver Steele
Date: Fri, 15 Jan 1988 05:21
Date: Fri, 15 Jan 1988 05:21
52 lines
2825 bytes
2825 bytes
gleicher@duke.cs.duke.edu (Michael Gleicher) writes:
} unsigned Book[][50]; doesn't work
} or
} extern unsigned Book[][50];
} Book = (void *) malloc(...) gives a bizzare error
steele@thorin.UUCP (Some Dyslexic Idiot) writes:
>Do you mean unsigned Book[50][]; ? What you've written isn't
>valid C, and should have given an error on the PC; if it didn't, that's
>a PC compiler incompability, not an LSC one.
Of course, Book[50][] is worse. unsigned Book[][50] is valid only as a
former parameter or an extern, and works in LSC as such. It isn't valid
as a global or local variable declaration, since the compiler can't figure
out how much storage to allocate, and doesn't work in these situations.
Book1[][50] isn't the same as (*Book4)[50] except as a formal parameter
declaration, although both Books can be used the same way in an
expression.
unsigned Book1[][50];
tells the compiler that Book1 is an array to be allocated in the data
segment, but it doesn't tell the compiler how big the array is, so the
compiler can't allocate it.
unsigned Book2[10][50];
tells the compiler how big the array is, too, but you knew that.
extern unsigned Book3[][50];
tells the compiler that Book3 is an array which is defined in another
file, so the compiler doesn't have to allocate Book3 when it hits the
declaration but it knows what to do with Book3 when it sees it in an
expression (plug in a constant reference off of A5, if the data segment is
stored in a place relative to A5). Since Book3 acts like a constant here,
any attempt to assign to it, such as
Book3 = (void *) malloc(...);
should "give a bizzare error".
unsigned (*Book4)[50];
declares a pointer to an array of unsigned, which can be used in
expressions synonymously with Book2 and Book3 just like str0 and str1 in
'char *str0, str1[50]' can be used synonymously, but which can be assigned
to, just like str0 but unlike str1. The syntax for assignment is
Book4 = (int (*)[50]) malloc(...);
of course :-). And then you can say stuff like
Book4[10][20] = 1234,
just as if Book4 were a real array.
------------------------------------------------------------------------------
Oliver Steele ...!{decvax,ihnp4}!mcnc!unc!steele
UNC-CH LING Senior steele@cs.unc.edu
Life is a negative-sum game.
Technical Details
Message-ID:
<698@thorin.cs.unc.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!mcnc!thorin!steeleReferences:
<10928@duke.cs.duke.edu> <696@thorin.cs.unc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!mcnc!thorin!steele From: steele@thorin.cs.unc.edu (Oliver Steele) Newsgroups: comp.sys.mac Subject: Re: LightSpeed C gripes Summary: Retraction Keywords: LightSpeed C no good, Mac 2, Gnu Chess Message-ID: <698@thorin.cs.unc.edu> Date: 15 Jan 88 05:21:49 GMT References: <10928@duke.cs.duke.edu> <696@thorin.cs.unc.edu> Reply-To: steele@thorin.UUCP (Oliver Steele) Organization: University of North Carolina, Chapel Hill Lines: 52