mjs@whuts.ATT.COM (SCHEUTZOW) (11/22/88)
> Reply-To: katzung@laidbak.UUCP (Brian Katzung) > Another bug... > > struct { int m; } sa[1]; > (1) sa->m = 0; /* Compiler chokes on this */ > (2) (&(*sa))->m = 1; /* But this works */ > > The compiler complains about applying -> to an array. > Line (1) seems like a misuse of the pointer operator to me; I would have written: sa[0].m = 0; (After all, it was declared as an array) Line (1) makes it past the lint checker on this machine, but just because our compiler accepts it doesn't mean that all of them must. I'm tempted to ramble about pointer- to-struct and pointer-to-array-of-struct, but I'll skip it. Line (2) creates a pointer because of the "&", so using the pointer operator shouldn't cause any trouble. Mike S. att!whuts!mjs
chris@mimsy.UUCP (Chris Torek) (11/27/88)
>>struct { int m; } sa[1]; >>sa->m = 0; /* Compiler chokes on this */ In article <5092@whuts.ATT.COM> mjs@whuts.ATT.COM (SCHEUTZOW) writes: >[This] seems like a misuse of the pointer operator to me; .... It is correct. An object of type `array of T' in an rvalue context is converted to an rvalue of type `pointer to T' whose value is the address of the 0'th array element. The left hand side of the `->' operator demands an rvalue expression of type `pointer to struct-or-union'; `sa' here becomes `pointer to struct <noname>', and the rhs `m' is a member of this structure, so all is fine. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris