Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Re: [AVR-Chat] C problem

Re: [AVR-Chat] C problem

2008-02-28 by np np

One huge huge hole with C in some microcontrollers is the loss of the status bits after a calculation.
Show quoted textHide quoted text
----- Original Message ----
From: David Kelly <dkelly@hiwaay.net>
To: AVR-Chat@yahoogroups.com
Sent: Thursday, 28 February, 2008 3:42:06 PM
Subject: Re: [AVR-Chat] C problem

On Thu, Feb 28, 2008 at 08:13:49AM -0000, bhadson2001 wrote:
> 
> unsigned char a;
> a=255*20/10;
> 
> it gives output 254
> 
> for
> a=255*200/100;
> 
> it gives output 111
> 
> why it gives different results.
> 
> it there any logical relationship.

The intermediate math is signed 16 bit integer. 255*200 = 51,000 which
is -14,546. Divide by 100 = -145 = 111 unsigned.

-- 
David Kelly N4HHE, dkelly@HiWAAY. net
============ ========= ========= ========= ========= ========= ========= ======
Whom computers would destroy, they must first drive mad.




      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Inbox. http://uk.docs.yahoo.com/nowyoucan.html

[Non-text portions of this message have been removed]

Re: [AVR-Chat] C problem

2008-02-29 by Russell Shaw

np np wrote:
> One huge huge hole with C in some microcontrollers is the loss of the status bits after a calculation.

C was designed for portability. There is no standard for how to implement
hardware status, so that is non-portable and too variable to implement in
C, especially as some CPUs may have no concept of conventional status
handling.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.