From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a9b0810d3106d9b8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!a11g2000pro.googlegroups.com!not-for-mail From: KK6GM Newsgroups: comp.lang.ada Subject: Re: Fun with C Date: Sat, 16 Apr 2011 23:26:14 -0700 (PDT) Organization: http://groups.google.com Message-ID: <54108d8d-4e7c-4901-bd5e-819d27720d48@a11g2000pro.googlegroups.com> References: <27cf3992-4132-4483-9110-adc7a089cd4a@e8g2000vbz.googlegroups.com> NNTP-Posting-Host: 71.137.110.174 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1303021574 10955 127.0.0.1 (17 Apr 2011 06:26:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 17 Apr 2011 06:26:14 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a11g2000pro.googlegroups.com; posting-host=71.137.110.174; posting-account=qZVz2QoAAAAN9WxYp-9jYb7jORc4Zqwt User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:18827 Date: 2011-04-16T23:26:14-07:00 List-Id: On Apr 16, 10:02=A0am, "George P." wrote: > Spend few days chasing bug in embedded C project which can drilled > down to this. Consider the following program, and all reasonable men > will expect the result to be negative. =A0Not in C, and it is not a > compiler bug :-( > > And offcorse none of the three comilers I cheched did not bother to > issue a warning at least.. > > #include > > int main() > { > =A0 =A0 =A0unsigned n =3D 128; > =A0 =A0 =A0int i =3D -2048; > =A0 =A0 =A0int r; > > =A0 =A0 =A0r =3D i / n; > > =A0 =A0 =A0printf("R =3D %d\n", r); > > =A0 =A0 =A0return 0; > > > > }- Hide quoted text - > > - Show quoted text - Wow and wow. I've been writing C all my adult life and I didn't realize this could or would happen. I would have said that the unsigned would be promoted to signed. I'm going to include this example in my push to use Ada in our next project.