home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!swrinde!sdd.hp.com!usc!howland.reston.ans.net!spool.mu.edu!sgiblab!munnari.oz.au!yarrina.connect.com.au!warrane.connect.com.au!g2syd!andrewc
- From: andrewc@g2syd.genasys.com.au (Andrew Congdon)
- Subject: const qualifier
- Message-ID: <1993Jan28.073947.6951@g2syd.genasys.com.au>
- Organization: Genasys II, Sydney, Australia
- Date: Thu, 28 Jan 1993 07:39:47 GMT
- Lines: 38
-
- I am still really confused about the use of the const qualifier. I'd be
- grateful if someone could point me at a clear demonstration of its use.
-
- I have a function which takes a parameter that is a 2 dimensional array
- which it will never modify. A similar function takes the same parameter
- type but does modify its contents. To make it clear I thought I'd make
- the former have a const qualified argument. Except for a recently
- patched IBM ANSI C compiler, all the ANSI C compilers here complain
- about the following:
-
- extern void
- fn(const float colours[][3]);
-
- static float colours[][3] = { { 1.0, 0.0, 0.0 } };
-
- fn2(void)
- {
- fn(colours);
- }
-
- The complaint is the parameter in the call to fn() does not match the
- prototype. The compilers seem much happier if the call is changed to:
-
- fn((const float (*)[3])colours);
-
- Why should the cast be necessary?
-
- The DEC complaint is at least amusing:
-
- const.c:9: error: In this statement, the referenced type of the
- pointer value "colours" is "array [3] of float", which is not compatible
- with "array [3] of float".
-
- --
- Andrew Congdon | Genasys II Pty Ltd
- | 13th Level, 33 Berry St, North Sydney, NSW, Australia
- | Phone: +61-2-954-0022 (-9930 FAX)
- | Internet: andrewc@g2syd.genasys.com.au
-