[comp.unix.questions] shared memory question/ array of structures

jeff@ge1ccj.Quotron.com (jeff marder) (10/05/90)

Suppose I want to define a shared memory segment that is an array of
structures.  Do I need to declare the array of structures in my program,
or only a pointer to an array of structures to make a shared memory
attach?   How do you declare a pointer to an array of structures?

cpcahil@virtech.uucp (Conor P. Cahill) (10/06/90)

In article <628@ge1ccj.Quotron.com> jeff@ge1ccj.Quotron.com (jeff marder) writes:
>
>Suppose I want to define a shared memory segment that is an array of
>structures.  Do I need to declare the array of structures in my program,
>or only a pointer to an array of structures to make a shared memory
>attach?

You could use an array of pointers to shared memory locations or
a pointer to an array of structures.

>  How do you declare a pointer to an array of structures?

cdecl> declare x as pointer to array 5 of int
int (*x)[5]
cdecl> declare x as pointer to array 5 of struct tmpstruct
struct tmpstruct (*x) [5]

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

chris@mimsy.umd.edu (Chris Torek) (10/06/90)

>In article <628@ge1ccj.Quotron.com> jeff@ge1ccj.Quotron.com (jeff marder)
asks:
>>Suppose I want to define a shared memory segment that is an array of
>>structures.  Do I need to declare the array of structures in my program,
>>or only a pointer to an array of structures to make a shared memory
>>attach?

In article <1990Oct05.182804.27340@virtech.uucp> cpcahil@virtech.uucp
(Conor P. Cahill) answers:
>You could use an array of pointers to shared memory locations or
>a pointer to an array of structures.

Or, more likely what is desired, you could use a pointer to a (single)
structure.  One of the keys to understanding C arrays and pointers is
the fact that a pointer that points *to* any single element of any array
may be used to access *any* element of that array.  If p points to
element 3 of array `a', then p `points at' ALL of a, and a[2] can be
obtained by naming p[-1] and a[111] can be obtained by naming p[98].
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris