Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!dayton!viper!john From: john@viper.UUCP Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: Assigning to Pointers Message-ID: <967@viper.UUCP> Date: Tue, 12-May-87 15:09:57 EDT Article-I.D.: viper.967 Posted: Tue May 12 15:09:57 1987 Date-Received: Fri, 15-May-87 04:48:20 EDT References: <3537@vrdxhq.UUCP> <857@killer.UUCP> Reply-To: john@viper.UUCP (John Stanley) Organization: DynaSoft Systems Lines: 77 Xref: utgpu comp.sys.ibm.pc:3495 comp.lang.c:2061 In article <857@killer.UUCP> jfh@killer.UUCP (John Haugh) writes: >In article <3537@vrdxhq.UUCP>, tom@vrdxhq.UUCP (Tom Welsh) writes: >> >> I want to do the following : >> >> >> int *aa[]; >This is not a pointer to an array. This is an array of pointers. So, >the assignment >> aa = 0x50000; >doesn't make much sense. If you want a pointer to an array, you could >try >int **aa; Correct so far.... > If you REALLY want a pointer to an array, how about >int *(aa[]); How about because it's not a pointer to an array? A pointer to an array of int would be: int (*aa)[]; What you gave ( int *(aa[]); ) is identical to ( int *aa[]; ) which is actualy an array of pointers to ints... The [] binds to aa with a higher precedence than the *. > My weakness is pointers to functions - So I see... If it's any consolation, it's taken me a few years to get to the point where I get them right most of the time. I know many programmers who're excelent programmers, but even after 5-10 years they still get function pointers wrong now and then... I suspect the problem Tom Welsh is having is from the incorrect (but often used) habit some programmers have of defining a pointer to an array of pointers in-the-parameter-list as: foo(aa) int *aa[]; { .... Now, because C "knows" that you can't pass an array, it translates the *aa[] into **aa but doesn't tell the programmer about it. Any reference to aa[x] is (per standard C) corectly converted to *(aa+x) which will work for an array or a pointer. Unfortunately for Tom, this doesn't work anywhere except as part of the parameter list. If you have the sample I gave above, then aa = (int**)0x50000; will work with no problem, but it won't work at-all if you try it with a non-function-argument variable since the identifier aa will then refer to a non-moveable array. Your best bet is to correctly define it as int **aa; in the first place and avoid using the [] for for a pointer in parameter lists to avoid future confusion... >I won't even bother with POINTER to FUNCTION returning POINTER to FUNCTION >returning an integer. Just for the hell of it... B-) ...: int (*((*foo)()))(); >Disclaimer: > I don't have the slightest idea what I am talking about. I can't > handle these problems either. Oh... (falseto voice) "Nevermind..." :) --- John Stanley (john@viper.UUCP) Software Consultant - DynaSoft Systems UUCP: ...{amdahl,ihnp4,rutgers}!{meccts,dayton}!viper!john