home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!concert!uvaarpa!darwin.sura.net!sgiblab!news.kpc.com!kpc!hollasch
- From: hollasch@kpc.com (Steve Hollasch)
- Subject: Re: What is meant by: double A[n,m]?
- Message-ID: <1992Nov18.223900.8941@kpc.com>
- Summary: Confusing, perhaps, but not meaningless.
- Sender: usenet@kpc.com
- Organization: Kubota Pacific Computer, Inc.
- References: <TORSTEIN.92Nov18125146@itekiris.kjemi.unit.no> <28363@castle.ed.ac.uk>
- Date: Wed, 18 Nov 1992 22:39:00 GMT
- Lines: 39
-
- torstein@itekiris.kjemi.unit.no (torstein hansen) writes:
- > As a newcomer to C, previously programming in Pascal, I used the
- > following declaration in one of my programs:
- >
- > double A[n,m];
- >
- > Has it something to do with the comma operator, discarding the first
- > value inside the braces?
-
- jlothian@castle.ed.ac.uk (J Lothian) writes:
- | I suspect that's exactly what's happening. The comma operator
- | evaluates both its arguments, returning the value of the right-
- | hand expression and throwing away the value of the left-hand one.
- | Presumably your C compiler is quite happy to do this evaluation
- | at compile-time, though I'm a little surprised that it didn't flag
- | this as an error, given that in this context the construction is
- | bound to be meaningless.
-
- Not true. First of all, the expression "A[index]" is not evaluated at
- compile time, nor is "A[flag,index]"; both of these will be evaluated at
- run time. Nor is this construct meaningless - consider the following
- fragment:
-
- return error_msgs [global_errno = ERR_SOMETHING, getindex()];
-
- where
-
- error_msgs is an array of pointers to error messages,
- global_errno is some encoded error value,
- and getindex() is a function that returns the error message index
- based on global_errno.
-
- A completely contrived example, but it should demonstrate that using a
- comma operator within an array subscript is not meaningless (though some
- might object to the above construct for reasons of style).
-
- ______________________________________________________________________________
- Steve Hollasch Kubota Pacific Computer, Inc.
- hollasch@kpc.com Santa Clara, California
-