Path: utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: typedef-ing an array Message-ID: <25585@mimsy.umd.edu> Date: 20 Jul 90 03:07:29 GMT References: <78627@srcsip.UUCP> <78633@srcsip.UUCP> <1990Jul3.231408.14315@everexn.uucp> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 36 Although I already followed up to the original question, I should correct something here: In article <1990Jul3.231408.14315@everexn.uucp> roger@everexn.uucp (Roger House) writes: >... The string "Silly old me" is of type "pointer to char". The type of a string constant is `array N of char', where N is one more than the number of characters in the string% (the extra one is for the final '\0' character). In this case the type is `array 13 of char'. The string was, however, in a value context and as such undergoes the usual transformation: In any value context, an object of type `array N of T' becomes a value of type `pointer to T' whose value is the address of the first (0th) element of the array. This rule is extremely important. Like the rule `a*b = b*a', it must simply be memorised as a Fact Of C. Given that and the rules of pointer arithmetic and indirection, you can derive a consistent method for dealing with arrays and pointers. ----- % I am intentionally ignoring multibyte strings here, as they mainly serve to confuse the issue. >In C you cannot assign a value to an array by using the assignment >operator "=". This is correct: an array is not a modifiable lvalue (i.e., it may not be assigned to). Note that an initialization (e.g., char x = 'f';) is not an assignment (under ANSI X3.159-1989 at least; in Classic C automatic initializers were semantically identical to assignments, but under New C aggregates are permitted here). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris