https://godbolt.org/z/e69b4Tqbs
>>109456418that'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
>>109456418ezfix: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
>>109456418No wonder they are retarded.
>>109456783"I avoid explicitness because it silences warnings" is not the win you think it is.
>>109457144C implicit casting is not rocket scienceif you do type_t a = bIt is equivalent totype_t a = (type_t) bThe 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.
type_t a = b
type_t a = (type_t) b
>>109456418Works fine with -O2. Let me guess, you need more?
>>109459437It's still undefined behaviorOP 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 Cnot 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.
>>109459736Not an argument, try again
>>109456418Writing bad code and still needing to use compiler flags for the UB, i take you are a rust frog
>>109456418tcc dont have the problem:https://godbolt.org/z/axaGc87PM
>>109460378yes, it was a statement, not an argument. thank you for proving your retardation with your retarded derivative reply.
>>109457144It is though.
>>109456418>my broken code is brokenWow, who would have thought
>>109462710>everything GCC dont like is broken
>>109456418clangger bros... this doesn't reproduce with g(od)c(hosen)c(ompiler)...
>>109459526Okay but why does the value of the unsigned int change after the one time it's set?
>>109456509Its 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.
>>109463147See >>109463357
>>109456418total goyware death
>>109463506since 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.
>>109463506why 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.
>>109463629Incorrect—if the standards committee did not want these optimization opportunities to exist they would define the behavior.
>>109464427this https://godbolt.org/z/e69b4Tqbs not okundefined variable cant change value mid airalso the only real C standard is tcc.exe
>>109461999
>>109464664>undefined variable cant change value mid airYes 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
>>109466669f-ck off
also this:https://desuarchive.org/g/thread/106861974https://desuarchive.org/g/thread/106843778https://desuarchive.org/g/thread/106554716https://desuarchive.org/g/thread/106015802https://desuarchive.org/g/thread/106375037https://desuarchive.org/g/thread/105155906https://desuarchive.org/g/thread/109303943https://desuarchive.org/g/thread/109303986
and this:https://pixel<cut>drain.com/u/ddx4whTQ
>>109464664
botted thread
>>109467017>>109464664