Closed MohamedGhardallou closed 2 years ago
In Blech number literals are unsized. You need a "size" here, you can write
const HOUR_IN_SEC = (60 : nat32) * 60
or even
const HOUR_IN_SEC : nat32 = (60 : nat16) * 60
which means the expression is of type nat16 and can be assigned to a nat32.
if you write
const HOUR_IN_SEC : nat32 = (60 : nat8) * 60
you will get an error, because the right side does not fit into a nat8
It was a decision not to have number literals of different types. Your example is one of the exceptional cases where you need a type annotation. See also: https://www.blech-lang.org/docs/user-manual/expressions/#annotated-literals
One more thing: Compile-time expressions are evaluated by the compiler. You can see the result in the generated C code.
Thanks for the detailed response. Yes i see that it's replaced by a value in the generated code. Thanks
Hello compiling this program
produces the following error :
error: Cannot resolve overloaded arithmetic operation on unsized literals '60' and '60'. --> prog.blc:5:30 [typing]
5 | const HOUR_IN_SEC : nat32 = 60 * 60 | ^^^^^^^ overloading not resolved