delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/04/09/11:15:34

Message-ID: <3AD1CE67.A6848ED4@cyberoptics.com>
From: Eric Rudd <rudd AT cyberoptics DOT com>
Organization: CyberOptics
X-Mailer: Mozilla 4.72 [en] (Win95; U)
X-Accept-Language: en,pdf
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: GCC 2.95.3 and C standard(s) + commandline switch problems
References: <4830 DOT 986817066 AT www1 DOT gmx DOT net>
Lines: 33
Date: Mon, 09 Apr 2001 09:59:51 -0500
NNTP-Posting-Host: 38.196.93.9
X-Trace: client 986828393 38.196.93.9 (Mon, 09 Apr 2001 10:59:53 EDT)
NNTP-Posting-Date: Mon, 09 Apr 2001 10:59:53 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

ahelm AT gmx DOT net wrote:

> Hi
> I'm having troubles with a subtle ANSI C standard problem and maybe some
> bugs in the DJGPP port of GCC (commandline switches).
>
> What type is the result of the multiplication of two unsigned short
> variables?
>
> The problem is that there is a difference between old and new ANSI
> standard.
>
> ANSI C (both standards) clearly state that the result of a binary
> arithmetic operation is of the same type as the inputs after applying the
> "usual arithmetic conversions" (to the inputs) when necessary.
>
> Following the rules in 6.2.1.5 in the old standard (usual arithmetic
> conversions), none of the rules apply until reaching the last:
> "Otherwise both operands have type int"

I think that your interpretation of C90 is correct.  I tried your little
program under Watcom C++ 10.0 and also found that the multiplicands got
promoted to int before multiplication.  I wonder if the C99 folks intended
for there to be a change in such arithmetic.  I would suggest re-posting the
standards questions to comp.std.c -- they chew on stuff like this all the
time, and would be better able to discuss the standards implications here.
This would seem to be one of those things that would break old code, though
the low 16 bits are the same, so if you assigned the product to another
unsigned short, you'd get the same answer under both standards.

-Eric Rudd
rudd AT cyberoptics DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019