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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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: g2news2.google.com!postnews.google.com!p6g2000vbn.googlegroups.com!not-for-mail From: "George P." Newsgroups: comp.lang.ada Subject: Re: Fun with C Date: Sat, 16 Apr 2011 15:03:27 -0700 (PDT) Organization: http://groups.google.com Message-ID: <9846a2a6-4006-4645-9857-71c93fd319eb@p6g2000vbn.googlegroups.com> References: <27cf3992-4132-4483-9110-adc7a089cd4a@e8g2000vbz.googlegroups.com> NNTP-Posting-Host: 63.88.115.178 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1302991407 8239 127.0.0.1 (16 Apr 2011 22:03:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 16 Apr 2011 22:03:27 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p6g2000vbn.googlegroups.com; posting-host=63.88.115.178; posting-account=VnNb3AoAAACTpRtCcTrcjmPX7cs92k1Q User-Agent: G2/1.0 X-HTTP-Via: 1.1 SPARKS X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16 GTB7.1 GTBA,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:19795 Date: 2011-04-16T15:03:27-07:00 List-Id: On Apr 16, 4:04=A0pm, "Nasser M. Abbasi" wrote: > On 4/16/2011 10:02 AM, 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 =A0 unsigned n =3D 128; > > =A0 =A0 =A0 int i =3D -2048; > > =A0 =A0 =A0 int r; > > > =A0 =A0 =A0 r =3D i / n; > > > =A0 =A0 =A0 printf("R =3D %d\n", r); > > > =A0 =A0 =A0 return 0; > > } > > $ gcc -Wall =A0t.c > $ ./a.out > R =3D 33554416 > > That is why we all love C. Best Job security in the world > for programmers. > > There are always "issues" to fix. =A0You see, you yourself had to > work for few days on this one. If you had used Ada, or any =A0other > more strongly typed languages, then you'll be done early, > then the manager will have come in and saw you sitting > doing nothing becuase your program is done, and you'll be out > of work. > > So, you should be very happy you are working on C. > > --Nasser Was difficult to find this one. Unsigned was used as counter to compute average which could have both signs. Were looking elsewhere since code seemed to be so logical: dividing on unsigned integer should always give the result less then argument. With C disregard to overflow, seems to be strange such a sudden concern to types converting everything to higher ranked unsigned. I do work in C/C++ on one project out of necessity (TI DSP). Despite very strict coding conventions this one still sneaked in. No issue for ADA and C# gives compile error (fair). Again, at least compiler warning will be nice IMHO.