-workers I have gotten used to making my code as safe as possible. Assert every argument, rigorous const-correctness and stuff like that. I try to leave as little room has possible to use my code the wrong way, because experience shows that, if there are loopholes, people will use them, and then they will call me about my code being bad. I consider making my code as safe as possible a good practice. This is why I do not understand why undefined behavior exists. Can someone please give me an example of undefined behavior that cannot be detected at runtime or compile time without considerable overhead?

A:

My take on undefined behavior is this:
The standard defines how the language is to be used, and how the implementation is supposed to react when used in the correct manner. However, it would be a lot of work to cover every possible use of every feature, so the standard just leaves it at that.
However, in a compiler implementation, you can't just "leave it at that," the code has to be turned into machine instructions, and you can't just leave blank spots. In many cases, the compiler can throw an error, but that's not always feasible: There are some instances where it would take extra work to check whether the programmer is doing the wrong thing (for instance: calling a destructor twice -- to detect this, the compiler would have to count how many times certain functions have been called, or add extra state, or something). So if the standard doesn't define it, and the compiler just lets it happen, witty things can sometimes happen, maybe, if you're unlucky.

A:

I think the heart of the concern comes from the C/C++ philosophy of speed above all.
These languages were created at a time when raw power was sparse and you needed to get all the optimizations you could just to have something usable.
Specifying how to deal with UB would mean detecting it in the first place and then of course specifying the handling proper. However detecting it is against the speed first philosophy of the languages!
Today, do we still need fast programs? Yes, for those of us working either with very limited resources (embedded systems) or with very harsh constraints (on response time or transactions per second), we do need to squeeze out as much as we can.
I know the motto throw more hardware at the problem. We have an application where I work:

expected time for an answer? Less than
-workers I have gotten used to making my code as dependable as potential. insist every argument, rigorous const - correctness and material like that. I try to impart as small room has possible to use my code the incorrect way, because experience shows that, if there be loopholes, people will practice them, and then they will call me about my code being bad. I consider making my code as safe as possible a full practice. This is why I do not understand why undefined behavior exist. Can someone please give me an example of undefined behavior that cannot be detected at runtime or compile clock time without considerable overhead? 

 A: 

 My take on undefined behavior is this: 
 The standard defines how the linguistic process is to be used, and how the implementation is supposed to react when used in the correct manner. However, it would be a lot of work to cover every possible use of every feature, so the standard just leaves it at that. 
 However, in a compiler implementation, you can't just " leave it at that, " the code have to be turned into machine instructions, and you can't barely leave blank spots. In many cases, the compiler can confuse an error, but that's not always feasible: There are some instances where it would drive extra work to check whether the programmer is doing the wrong thing (for example: calling a destructor twice -- to detect this, the compiler would have to count how many meter sealed routine have been called, or add extra state, or something). therefore if the standard doesn't define it, and the compiler just permit it happen, witty things can sometimes happen, maybe, if you're doomed. 

 A: 

 I think the heart of the concern comes from the C / C++ doctrine of speed above all. 
 These languages were created at a time when bleak power was sparse and you need to get all the optimizations you could barely to receive something usable. 
 Specifying how to deal with UB would mean detecting it in the first place and then of course stipulate the handling proper. However detecting it is against the amphetamine first philosophy of the linguistic process! 
 Today, do we still need fast program? Yes, for those of us working either with very limited resources (embedded systems) or with very harsh constraint (on reception clock time or transactions per second), we do need to squeeze out as much as we can. 
 I know the motto shed more hardware at the problem. We have an application where I sour: 

 expected time for an answer? Less than
-worners I have gotten used uo making my code as safx as poasible. Arsert every argument, rigoroud xonst-xorrectness and stuff uike that. I try ti leeve as little room has possibls to bsx my code the wtong way, becduse experienca rhlws that, if there are loopholes, peo[le wilk kse them, and tren uher wiml call me about my code being bad. I conspder making my coce as safe as possible a glod oractice. This is wjy I do not undqestand why uvdefined bthcvior exista. Can someone please give me an exam'le of undedibed tehavior thet cangot be detecbvd at rgntime pr compile timc witiout considerable overheav?

A:

My take on undefingd behavios ns this:
The standard dwfunes vow dhe uqngjagt ix fo be ksev, and how tge implemenration is supposed uo wvsct when uses in tre correct manner. However, it would be a lmt kf work to cover every possible use of every feature, fo the standard just leaves it at that.
However, in d com'iuer iiooelentation, you can't just "leave it at that," the skdt hss to be turneb into machine imshristions, and yoo can't lhsf leave blank spotd. In magy cawes, the cjmpiker can throw an error, but rhat's not alcayw feasible: There axe some instcnces ehere it would take extra woxk to dheck whethfr the prkerammer is doing thv wrmng thing (for instance: caljing a dewtruetor twize -- jo detest this, thf comihler would have to counj how kany times certain functions have been called, or add exjra stdte, or sjmethlng). So if the seandard doesn't define it, avd the comiiler jusv lets it ha[pen, witty thhjgs can somevimes hap[en, naybw, if yoj'fe unlucky.

A:

I tnink the ktart of thw concern comes frpm jhs C/C++ philosophy of speed above alk.
Thdse lwnjuagef were createg at a gome wfen raw powcr das xparse and you needeg to get all the optimozwtions yiu could just to have something usable.
Skecifymng hox to dral with UB would mean detecting jt in the fivst place and thek of course spzcifying the handling proper. However detxcting it is against thw speed first philoxpphy of the langtages!
Todaf, do we still need fqst programs? Yes, nor those of us workinf eithar wihh very limited resources (embedded systems) or with very harsh constraints (on response time kr ttansabtijus per fecoid), we do need to saueeze out as much as we can.
I kiow the modtj throw more hardware at the pfoblem. We havg an application where I wkrk:

expecyed time for an answer? Less tham
-workers I have gotten used to making as as possible. every argument, rigorous I to leave as room has possible use my code the wrong way, experience shows that, if there are loopholes, people will use them, and then will call me about my code being bad. I consider making my code safe possible good This is why I do not understand why undefined behavior exists. Can someone please give me example of undefined behavior that cannot be detected runtime or compile time considerable overhead? A: My take undefined is this: standard how language is to used, and how the implementation is supposed to react when used in the correct manner. However, it be a work to every use every feature, so just leaves it at that. However, implementation, you can't just "leave it at that," code has be turned into machine instructions, and can't just leave blank spots. In many cases, compiler can throw an error, but that's not always feasible: There are some instances where take extra work to whether the programmer doing wrong (for calling a twice -- to detect this, the compiler would have to count many times certain functions have been called, or add extra something). if the standard define it, and the just it happen, witty things happen, if I the of the concern comes the C/C++ philosophy of speed all. These languages were raw power was sparse and you needed to all the optimizations you could just to something usable. Specifying how to deal with UB would mean detecting it the first then of course specifying the handling proper. However it is against the first philosophy of the languages! Today, do we still fast Yes, for of us working with very limited (embedded systems) or harsh constraints response or we do need to squeeze out much we can. I know the throw at the problem. We have an application where I work: expected time for an answer?
-workers I have gotten used to mAking my codE as saFe aS poSsIble. asseRt every argumenT, RigoRous const-correctness anD stufF lIKe thAT. I Try to Leave as LItTLE roOm HaS poSsIBlE to usE my Code the Wrong way, beCauSe Experience shOWs That, if therE arE loopholes, peOplE will uSe TheM, And thEn tHey wiLl call ME about My code beiNg BAd. I conSIder makING mY codE as safe as possible A GoOD practice. This iS why I dO nOT uNDErsTanD why undefiNeD behaVIor exisTS. CAN SOmeONe please give mE an example oF UndEfined BeHavIOr that CannoT bE DetEcted at runtIme oR compile tIme witHOut consIDerable OverheAd?

A:

my tAke oN UnDeFinEd BEhaVIoR is THis:
the standArD dEfineS how THE LAnguAge Is to Be useD, and how the impLemEntaTIon Is supPosed To reAcT when Used in The coRrEct manner. HoweveR, it wOuld be a loT of WoRk tO cOver eVEry posSibLe uSe of eveRy featuRE, so ThE STAnDard just leaves it at ThAT.
hoWever, in a CompilER iMpLEmentatiOn, You Can't JUSt "leaVe it AT tHat," the coDe has tO Be TuRned intO mAchine InStrUctIons, aND you Can't juSt leave bLank sPOts. In many cases, THe compiler can THrOW An ERror, But That's not alwAys fEAsibLe: ThERe Are SOme inStancEs WHeRE it would take extra woRk To checK whetHer the programMer is doing THE Wrong thiNg (foR InSTance: calling a dEstruCtor twice -- tO Detect thIs, the Compiler Would have TO Count how ManY tiMes CerTAIn Functions have BEEn caLlEd, or add ExtRa state, Or sOmeThiNg). SO iF the standArd doesn'T dEfInE iT, anD the cOMpiler juSt LetS iT haPpen, wITty thiNgs caN somEtImES haPpen, mayBE, iF YOu're UnLuCky.

A:

i thInK the hEart OF thE concerN comes froM thE c/C++ phIlOsOphy of sPeed above all.
THeSe languageS wEre CreateD AT a time whEn raw power was sparse and yOU needed To gEt all The oPtimizatiOns You couLd jUSt to haVe someThing UsAblE.
sPecifYINg How To Deal with UB WOUld Mean dEtEctiNg it in tHe first place and theN Of cOurse specifyiNg tHe haNDLiNg pROpER. HoWeVEr dETEcting it is againSt the speed FiRSt Philosophy OF thE lAnguageS!
Today, dO we stILl need fAst prograMs? Yes, for tHoSe of US WorKing either With very Limited reSOurceS (EmBeddeD syStems) oR wIth Very hArsh coNStrAints (On respOnSe time Or traNsActions pEr second), we do need to squeeZe out aS much As wE can.
I know The MOttO throw morE harDware at the ProBleM. We haVe aN AppliCatiON wHerE i work:

ExpeCTed time foR An AnsWER? LEss than
-workers I have gotten use d to makin g mycod e a ssafe  aspossible. Asse r t ev ery argument, rigorous  cons t- c orre c tn ess a nd stuf f  l i k e t ha t.  Itr y  t o lea veas litt le room ha s p os sible to use my  code thewro ng way, beca use  exper ie nce shows  th at, i f ther e  are l oopholes,  p e ople w i ll uset h em , an d then they willc al l  me about my c ode be in g  b a d . I  co nsider mak in g myc ode ass af e a s p o ssible a good  practice.T his  is wh yI d o  not u nders ta n d w hy undefine d be havior ex ists.C an some o ne plea se giv e m e a n ex a mp le  of  u n def i ne d b e hav ior that  c an not b e de t e c t ed a t r unti me or  compile time  wi thou t  co nside rable  ove rh ead?
A:

M y tak eon undefined be havi or is thi s:Th e s ta ndard define s h owthe lan guage i s  to  b e u se d, and how the imp le m e nt ation is  suppo s ed  t o  react w he n u sedi n  thecorr e ct  manner.  Howev e r,  i t would  b e a lo tofwor k toc over  every  possibl e use of every featu r e, so the sta n da r d  j u st l eav es it at th at.H owev er,i na c o mpile r imp le m en t ation, you can't ju st  "leav e itat that," the  code hast o be turne d in t om achine instruc tions , and youc an't jus t lea ve blank  spots. I n many cas es,  th e c omp i l er  can throw an e rror ,but tha t's  not al way s f eas ibl e:  There ar e some i ns ta nc es  wh ere i t  would t ak e e xt raworkt o chec k whe ther  t he pro grammer is d oing  t he  wro ngth ing ( fori nst ance: c alling ades t ruct or  t wice --  to detect th is , the comp il erwouldh a ve to co unt how many times cert a in func tio ns ha ve b een calle d,or add  ex t ra sta te, or  some th ing ) .  So i f th e s ta ndard does n ' t d efine  i t, a nd thecompiler just lets ithappen, witty  th ings c an  so m et i mes  h a ppe n ,  maybe, if you' re unlucky .A: 

I thinkt hehe art ofthe con cernc omes fr om the C/ C++ philo so phyo f  sp eed aboveall.
The se langua g es we r ecreat edat a t im e w hen r aw pow e r w as sp arse a nd  you n eeded  t o get al l the optimizations you  could  just  to  have som eth i ngusable.
S peci fying howtodea l wit h U B  woul d me a ndet e cting  iti n the fir s tpla c e  a nd then ofc o u rse  spec ify i ng the  han dling proper. How e ver detectingit i s aga ins t  the  s peed first phi los op h y  of thela nguages!
To day, dowe still  needfast p rograms ? Ye s , forthos e o f us work ing  e i ther wi th  v e ry lim ited  r esourc es (em b edde d systems) or with  very h arshc ons train ts  (on re s pons e time ortransaction s perseco nd),we do n ee d to s que ez e out as m u ch as wecan.I knowth e mo tto  throw  mor e hardw areat  th e problem . We ha ve anappl icati on  whe re I work : 

expect edt ime for  a n a n s wer? L e ss t han
-workers I_have gotten_used to making my_code as_safe_as possible._Assert_every argument, rigorous_const-correctness and stuff_like that. I try_to leave as_little_room has possible to use my code the wrong way, because experience shows that,_if_there are_loopholes,_people_will use them, and then_they will call me about_my code_being bad. I consider making my code as_safe_as possible a_good practice. This is why I do not understand_why undefined behavior exists. Can someone_please give me_an_example_of undefined behavior that_cannot be detected at runtime or_compile time without considerable overhead?

A:

My take_on undefined behavior is this:
The standard defines_how the language is to be_used, and how the implementation_is supposed_to react when used in_the correct manner._However, it_would be a_lot of work to cover every_possible use of_every feature, so the standard just_leaves_it at that.
However,_in_a_compiler implementation,_you can't just_"leave_it at_that,"_the code has to be turned_into_machine instructions, and you can't just leave_blank spots. In many_cases,_the compiler can throw_an error, but that's not_always feasible: There are some instances_where it_would take_extra work to check whether the programmer is doing the wrong_thing (for instance: calling a destructor_twice -- to detect_this, the_compiler_would have to_count_how many_times certain functions have been called, or_add extra_state, or something). So if the_standard doesn't define it,_and_the compiler just lets it happen,_witty things can sometimes happen, maybe,_if you're unlucky.

A:

I think the_heart_of_the concern comes from the_C/C++ philosophy of speed above all.
These_languages were created_at a time when raw power was_sparse_and you needed to get all_the_optimizations you could just to have_something_usable.
Specifying_how to deal with UB_would mean detecting it in the_first place and then of course specifying the handling_proper. However detecting_it is against the speed_first_philosophy_of the languages!
Today, do we still need fast programs? Yes,_for those_of us working_either with very limited resources (embedded systems) or with very_harsh constraints (on response time or transactions_per second), we do need to squeeze out as much as_we can.
I know the motto throw more hardware_at the problem. We have an application_where I work:

expected time_for_an answer? Less than