Path: utzoo!attcan!uunet!mcsun!ukc!edcastle!elee24 From: elee24@castle.ed.ac.uk (H Bruce) Newsgroups: comp.lang.c Subject: Type conversion within arithmetic expressions. What does ANSI say ? Message-ID: <6584@castle.ed.ac.uk> Date: 4 Oct 90 11:16:15 GMT Organization: Dept. Electrical Engineering, Edinburgh University, Scotland, UK. Lines: 21 How should the following code fragment compile ? unsigned char x,y; unsigned short int z; z=x*y; According to the ANSI standard, if the result of x*y exceeds 255, will all 16 bits be copied to z or only the lower 8 ? (i.e if x=2 and y=200 does z=400 or 400%256 ?) I have a C compiler for the 8051 which does not copy the upper byte across even if z=x*y is replaced with z=(unsigned short int)x*y. I want to confirm that this is a bug. Microsoft C does convert the result into 16 bits without a type cast. I can't find reference to this in any "ANSI" C books that we have. Thanks, Henry Bruce.