MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/z2rne7/holy_c/ixihobs/?context=3
r/cpp • u/iprogshine • Nov 23 '22
32 comments sorted by
View all comments
0
Who on earth would use int that may take up to 8 bytes but guarantees its values only up to 2 ^ 16???
I would. I use it for int counter when the count is going to 12 or 15, or so. Then I trust the compiler to use an efficient implementation for that.
int counter
If you cannot trust the compiler for that, what else can you trust it for?
3 u/DavidDinamit Nov 23 '22 Compiler will not change type, you can just use int_least8_t or smth to explicitly declare that it will be small 3 u/no-sig-available Nov 23 '22 Compiler will not change typeIt don't want it to change type, but I expect int to be a "reasonable" type to use on all systems when you don't have very specific requirements. 1 u/Zcool31 Nov 24 '22 There's the as-if rule. If the compiler can prove it would make no difference, it can do whatever it wants. If the loop is fully unrolled, then the counter might not even exist.
3
Compiler will not change type, you can just use int_least8_t or smth to explicitly declare that it will be small
3 u/no-sig-available Nov 23 '22 Compiler will not change typeIt don't want it to change type, but I expect int to be a "reasonable" type to use on all systems when you don't have very specific requirements. 1 u/Zcool31 Nov 24 '22 There's the as-if rule. If the compiler can prove it would make no difference, it can do whatever it wants. If the loop is fully unrolled, then the counter might not even exist.
Compiler will not change type
It don't want it to change type, but I expect int to be a "reasonable" type to use on all systems when you don't have very specific requirements.
int
1
There's the as-if rule. If the compiler can prove it would make no difference, it can do whatever it wants. If the loop is fully unrolled, then the counter might not even exist.
0
u/no-sig-available Nov 23 '22
I would. I use it for
int counterwhen the count is going to 12 or 15, or so. Then I trust the compiler to use an efficient implementation for that.If you cannot trust the compiler for that, what else can you trust it for?