Limits of Nat type in Shapeless

I will attempt one myself. I will gladly accept a better answer from Travis Brown or Miles Sabin. Nat can currently not be used to represent large numbers In the current implementation of Nat, the value corresponds to the number of nested shapeless.Succ[] types: scala> Nat(3) res10: shapeless.Succ[shapeless.Succ[shapeless.Succ[shapeless._0]]] = Succ() So to represent the number … Read more

Can I hint the optimizer by giving the range of an integer?

Yes, it is possible. For example, for gcc you can use __builtin_unreachable to tell the compiler about impossible conditions, like so: if (value < 0 || value > 36) __builtin_unreachable(); We can wrap the condition above in a macro: #define assume(cond) do { if (!(cond)) __builtin_unreachable(); } while (0) And use it like so: assume(x … Read more

Compiler changes printf to puts

Am I correct in assuming that compiler ‘introspected my string’, or there is another explanation of this? Yes, this is exactly what happens. It’s a pretty simple and common optimization done by the compiler. Since your first printf() call is just: printf(“Hello world\n”); It’s equivalent to: puts(“Hello world”); Since puts() does not need to scan … Read more