> On 08/15/2024 6:10 PM EDT Mike Katz via cctalk <cctalk@classiccmp.org> wrote:
>

I'm pretty certain you are wrong about the byte case below.  The C standard 
says something about no math will be done smaller than a short.  I don't have 
it handy so can't quote exactly.
But what that means is before the two bytes are added, they are promoted to 
short / uint16_t and then added.


> int foo( void )
> {
> uint32_t Long1 = 10;
> uint32_t Long2 = 20;
> uint16_t Short1 = 10;
> unit16_t Short2 = 20;
> uint8_t Byte1 = 10;
> uint8_t Byte2 = 20;
> //
...
> // Everything to the right of the equals will not be promoted at
> all, the math will be performed and the result will be promoted to a
> uint16 when assigned.
> //
> Short1 = Byte1 + Byte2;
>

In this program segment:

uint8_t a = 255;
uint8_t b = 255;
uint16_t c = 0;
c = a + b;
printf("c: %d \n", c);

it will print 510 instead of the 254 that would result if it were added as 
bytes.

Will


Grownups never understand anything by themselves and it is tiresome for 
children to be always and forever explaining things to them,

Antoine de Saint-Exupery in The Little Prince

Reply via email to