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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC 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-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: "Nasser M. Abbasi" Newsgroups: comp.lang.ada Subject: Re: Fun with C Date: Sat, 16 Apr 2011 13:04:05 -0700 Organization: Aioe.org NNTP Server Message-ID: References: <27cf3992-4132-4483-9110-adc7a089cd4a@e8g2000vbz.googlegroups.com> Reply-To: nma@12000.org NNTP-Posting-Host: tUYQ4Ty9mMw9Pdc8TJRFQA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 X-Notice: Filtered by postfilter v. 0.8.2 Xref: g2news1.google.com comp.lang.ada:18821 Date: 2011-04-16T13:04:05-07:00 List-Id: 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. Not 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() > { > unsigned n = 128; > int i = -2048; > int r; > > r = i / n; > > printf("R = %d\n", r); > > return 0; > } $ gcc -Wall t.c $ ./a.out R = 33554416 That is why we all love C. Best Job security in the world for programmers. There are always "issues" to fix. You see, you yourself had to work for few days on this one. If you had used Ada, or any other 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