Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!apple!netcom!avery From: avery@netcom.UUCP (Avery Colter) Newsgroups: comp.lang.c Subject: Re: Const Usage... Message-ID: <17858@netcom.UUCP> Date: 1 Dec 90 21:26:02 GMT Organization: Netcom- The Bay Area's Public Access Unix System {408 241-9760 guest} Lines: 49 Steven W Orr wrote: > Where do const keywords fit into this scheme? All I want to do is be > able to say something outrageous like > X is a constant pointer to a function that returns a constant > pointer to a constant array of constant ints. How could a function return a constant??? Hmmmm. All I can figure is that the consts would only be applicable to the declaration of other variables which will be used to dereference the variable above. I mean, this looks like: const int (*(*x)())[]. I like to use backward thinking with declarations, it helps me visualize what is actually being said. So, ints are the type of values in an array pointed to by the result of a function pointed to by x. I just tried running const int (* const (* const x)())[] through my compiler. It didn't take. So I can only gather that const will only be accepted at the start of the line or immediately after the outermost type. I think that the const marks x as being constant, regardless of what type it ultimately is. I still don't think you can have a function returning a const. I don't think you need to either, as parameters to a function are never changed on the level of the program that is calling that function, and returning a const means that the value returned by the function is always the same (at least that's the only way I can see to actually do this). Thus, to achieve that step, you would have the constant pointer point only to functions which are going to always return the same value regardless of the input parameters. What is being returned is a pointer to an array. Now, what is a constant array? There is no real meaning to this, as an array always has the same number of legal elements. Does a constant array mean all its elements are constant? Then saying "a constant array of constant ints" is redundant. Now, if the leading const makes x itself constant, then there is the question of how one binds the elements of the array to be constant. One might have to create the constant arrays of ints separately, and link x to them later. -- Avery Ray Colter {apple|claris}!netcom!avery {decwrl|mips|sgi}!btr!elfcat (415) 839-4567 "I feel love has got to come on and I want it: Something big and lovely!" - The B-52s, "Channel Z" Brought to you by Super Global Mega Corp .com