Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!mcvax!targon!romke From: romke@targon.UUCP (Romke Teerenstra) Newsgroups: comp.lang.c,comp.unix.wizards Subject: void declarations and casts Message-ID: <359@targon.UUCP> Date: Thu, 22-Oct-87 12:06:20 EST Article-I.D.: targon.359 Posted: Thu Oct 22 12:06:20 1987 Date-Received: Sun, 25-Oct-87 03:13:22 EST Reply-To: romke@targon.UUCP (Romke Teerenstra) Followup-To: comp.lang.c Organization: Nixdorf Computer BV., OSP, P.O. Box 29,Vianen, The Netherlands Lines: 35 Keywords: void, casts, declarations, assignments Xref: mnetor comp.lang.c:5080 comp.unix.wizards:5052 This afternoon I had this weird idea to print void values, and to cast values to void, just to see what would come out. My thoughts were : since void is a type, I can declare such a variable. So I can assign a value of that type to it. So I can cast something, say an integer, to it. So I should be ble to write a program what does just that. To my suprise however, this didn't even compile on the two types of machines we have here. One compiler complained about a void type being declared of which he didn't know the size, and the other just stopped, because he couldn't cast a value to void. After talking it over with two of my collegues, We think this program is legal, but don't know for sure. So I ask you: 1 Is this program legal? 2 If not, what is wrong with it? 3 If it is, what should be printed? #include main() { void v; v = (void)345; printf("%d %c %X\n",(int)v,(char)v,(int)v); } As this is cross-posted, please send Follow-ups to comp.lang.c Romke