[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 1777228172667306.png (498 KB, 857x1200)
498 KB PNG
https://godbolt.org/z/e69b4Tqbs
>>
>>109456418
that's nothing. you slap "-fsanitize=undefined" and you're good to go. there is much worse.
now why it wouldn't be a compile error, especially since this is all trivial to const-eval? because it's a STANDARD SAAR. an INTERNATIONAL STANDARD SAAR. my (((based e-celeb))) told me rust is tranny SAAR. and undefined behavior is important for performance SAAR.
but more seriously, there should be a warning for this.
>>
my favorite part of undefined behavior is that it gives the compiler permission to do anything whatsoever even if it has nothing to do with the particular part that was undefined
>>
maybe it isn't checked at compile time because real world instances of this aren't so trivial and very hard/ expensive to check
>>
>>109456418
ezfix:
just dont be a retard lamao
>>
>>109456496
>there should be a warning for this.
There is if you remove the cast, it then tells you
<source>:4:22: warning: implicit conversion of out of range value from 'double' to 'unsigned int' is undefined [-Wliteral-conversion]
Literal self own because OP doesn't know about implicit casting, I never cast unless I really know what I'm doing or the compiler warns me about it because I use -Wconversion
>>
>>109456418
No wonder they are retarded.
>>
>>109456783
"I avoid explicitness because it silences warnings" is not the win you think it is.
>>
>>109457144
C implicit casting is not rocket science
if you do
type_t a = b

It is equivalent to
type_t a = (type_t) b

The only difference is that the compiler will trust you more with the latter and will not emit warnings.
I do explicitly cast later if appropriate after reviewing the compiler warnings, the point is you should try to minimize explicit casting because it's one of the biggest footguns in C and the compiler won't even warn you if you do something stupid like OP.
>>
>>109456418
Works fine with -O2. Let me guess, you need more?
>>
>>109459437
It's still undefined behavior
OP is retarded because he's casting an out of range double to an unsigned int, his program would be free of undefined behavior if he changed all "unsigned int" to "double"
>>
>>109459435
>you should try to minimize explicit casting because it's one of the biggest footguns in C
not even top 10, and you're a retard for thinking this is the case, writing code where you would think that this is the case, and your "solution" to the problem.
>>
>>109459736
Not an argument, try again
>>
File: c-man.jpg (94 KB, 1080x1348)
94 KB JPG
>>109456418
Writing bad code and still needing to use compiler flags for the UB, i take you are a rust frog
>>
>>109456418
tcc dont have the problem:
https://godbolt.org/z/axaGc87PM
>>
>>109460378
yes, it was a statement, not an argument. thank you for proving your retardation with your retarded derivative reply.
>>
>>109457144
It is though.
>>
>>109456418
>my broken code is broken
Wow, who would have thought
>>
>>109462710
>everything GCC dont like is broken
>>
File: 1767948682849539.jpg (219 KB, 443x554)
219 KB JPG
>>109456418
clangger bros... this doesn't reproduce with g(od)c(hosen)c(ompiler)...
>>
>>109459526
Okay but why does the value of the unsigned int change after the one time it's set?
>>
>>109456509
Its just gcc and clang maliciously interpreting the standard. Standards are intended to be read in good faith, not treated like a legal document to find exploits in.
>>
>>109463147
See >>109463357
>>
>>109456418
total goyware death
>>
>>109463506
since it's undefined behavior, the compiled code just reads whatever random value stored in a register each time. and this is a good thing for maximum performance SAAR.
also this thread is full of posers who clearly can't even hello-world. for example this does happen with -O2 using the same compiler from OP (clang), and doesn't happen with GCC.
>>
>>109463506
why wouldn't the value of the unsigned int change after the one time it's set? if you were the value of an unsigned int you'd change after the one time you were set too.
>>
>>109463629
Incorrect—if the standards committee did not want these optimization opportunities to exist they would define the behavior.
>>
>>109464427
this https://godbolt.org/z/e69b4Tqbs not ok
undefined variable cant change value mid air
also the only real C standard is tcc.exe
>>
File: Screenshot 2026-07-27.png (52 KB, 653x396)
52 KB PNG
>>
>>109461999
>>
>>109464664
>undefined variable cant change value mid air
Yes they can, uninitialized variables are not stable, that's like undefined behavior 101, it's like you guys never taken a lecture on undefined behavior:
https://godbolt.org/z/98KEcG5of
>>
>>109466669
f-ck off
>>
also this:
https://desuarchive.org/g/thread/106861974
https://desuarchive.org/g/thread/106843778
https://desuarchive.org/g/thread/106554716
https://desuarchive.org/g/thread/106015802
https://desuarchive.org/g/thread/106375037
https://desuarchive.org/g/thread/105155906
https://desuarchive.org/g/thread/109303943
https://desuarchive.org/g/thread/109303986
>>
and this:
https://pixel<cut>drain.com/u/ddx4whTQ
>>
>>109464664
>>
botted thread
>>
>>109467017
>>109464664



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.