Forums Register Login

Iimplicit cast

+Pie Number of slices to send: Send
byte b=127;
byte c=126;
byte d=b-c;
In the third line the compiler complains .
It seams that the result is casted to int implicitly when two number calculate, but why?
And are there any other cases do the implicit cast appears ?
+Pie Number of slices to send: Send
but it is compiled!
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
From Kathy/Bert 's book, page 148-149: "the result of an expression involving anything int-sized or smaller is always an int. In other words, add two bytes together and you'll get an int."
So the compiler will complain that it can't convert int to byte, you need to explicit case to byte.
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 609 times.
Similar Threads
assignment doubt
Downcasting to Byte
Primitive variable assignments
byte
Automatic promotion of Variables
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:38:40.