Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: Assigning to Pointers Message-ID: <6495@mimsy.UUCP> Date: Wed, 29-Apr-87 13:23:43 EDT Article-I.D.: mimsy.6495 Posted: Wed Apr 29 13:23:43 1987 Date-Received: Sat, 2-May-87 02:46:56 EDT References: <3537@vrdxhq.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 73 Xref: mnetor comp.sys.ibm.pc:3635 comp.lang.c:1979 In article <3537@vrdxhq.UUCP> tom@vrdxhq.UUCP (Tom Welsh) writes: >This may be a dumb question, No, pointers and arrays and their interconversions are a common confusion point in C. >but could someone please explain to me how I assign an absolute >address to a pointer to an array? Given your example, you should use a pointer, not a pointer to an array. The C language assumes a flat memory space*, and given this assumption, a single pointer can tell you everything you need to know about a one-dimensional array save its size (which C does not use anyway, in this case). (*The flat space is only per data object, which allows segmented implementations on the 80x86.) >int *aa[]; % cdecl explain int *aa[] declare aa as array of pointer to int % In other words, this is an array of unspecified size (which is treated as though it were an `extern' definition, and allocates no memory, but, at least on Unix compilers, does set the symbol), each member of which points to zero or more integers. >-- or even better -- >struct POINTER_PARTS > { > unsigned offset_part; > unsigned segment_part; > } >union POINTER_ACCESS > { > struct POINTER_PARTS pp; > int *far_pointer; > } >union POINTER_ACCESS upa; >upa.pp.segment_part = 0x5000; >upa.pp.offset_part = 0x0; >aa = upa.far_pointer; This is indeed better: Simply leave out the final assignment, and use = upa.far_pointer[]; If you need a separate variable: int *aa; union POINTER_ACCESS upa; ... set upa ... aa = upa.far_pointer; `int *aa' is a pointer to a block of memory just as much as it is a pointer to a single `int'. The only thing that distinguishes the two is the programmer. (Yes, one can argue for `int (*aa)[]', but the current dpANS does not allow this declaration---though it does allow `int ar[]; &ar', in which &ar has type int (*)[]!) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu