3 ms·
I take it you've never made a mistake programming before then? A relatively trivial example is passing by const reference [0] While it's fairly clear in this ex
by maccard 9y ago
I take it you've never made a mistake programming before then? A relatively trivial example is passing by const reference [0]
While it's fairly clear in this example that you're getting a reference to a local variable, it can easily slip through if you pass something through a level or two of a function. Note there's no compiler warning for this. It also (probably) won't show up until you actually try and use St.m_x at some point, which may be in a very different place to where it was initialised. In most cases, if it shows up in an optimised build, you'll get next to 0 useful information from a debugger/stack trace.
[0] https://godbolt.org/g/XTh5Mv https://godbolt.org/g/XTh5Mv
- futurix 9y agoMy beef here is with the word 'random'. Mistakes don't make for random crashes - hard to trace perhaps, but not random.
- stinos 9y ago> not random Not so sure about that. Here's a mistake: have a floating point variable somewhere and then don't initialize it. On it's first use, multiply it by 0.0. What do you think the chances are the result is 0.0? Hint: nan * 0.0 == nan, and there are many nan representations out there, so it solely depends on what pattern the memory location for that variable is initialized with. So unless your compiler created a bunch of code to initialize the memory for you, which it does not always do, I'd consider that pretty random.
- futurix 9y agoWell, yes, but it is randomness of a mistake - not randomness of the language. If you are going to shoot yourself in the foot, I guess the wound would be pretty randomly located - but that is not the fault of the gun manufacturer.