Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Indefinite-length array as member of struct: how? Keywords: char string [] [0] [1] Message-ID: <18518@mimsy.UUCP> Date: 12 Jul 89 21:01:16 GMT References: <7360@c3pe.UUCP> <321@yetti.UUCP> <18492@mimsy.UUCP> <2948@nmtsun.nmt.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 37 (I should change the title, but cannot think of a better one.) >In article <18492@mimsy.UUCP> I wrote: >> char string[SIZE]; ... *string = ; >>is legal ... In article <2948@nmtsun.nmt.edu> dwho@nmtsun.nmt.edu (David Olix) writes: >I am not one to be picky (usually), but isn't *string (a.k.a. string[0]) >of type char? If so, any expression yeilding a result of type char >would be legal. It would, except that no expression yeilds a result of type `char' by the time one gets around to doing assignment, because the value promotes to one of type `int'. (The exact duration of the `char' type really depends on your compiler. The longer the compiler retains the type, the more likely it is to generate decent code. But in principle, `char c, d; c = d;' means `fetch d, widen to int, narrow to char, store in c'.) >Yes, an integer expression would also be legal, but depending on the >result of the expression and the sizes of char and int on the particular >machine you could end up losing bits. As long as we are being picky: `integer expression' includes values of type `long'. At any rate, the situation is possibly worse: code such as char c; c = 12345; is allowed (by the pANS) to produce weird results such as having the display leap off your desk, run in circles, then turn into a butterfly. The value of that integer-expression must fit in an object of type `char', or the result of the assignment is {un or implementation}- defined. (I cannot recall which offhand.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris