Quantcast
Channel: Does the C++ standard allow for an uninitialized bool to crash a program? - Stack Overflow
Browsing latest articles
Browse All 7 View Live

Answer by Tom Tanner for Does the C++ standard allow for an uninitialized...

Summarising your question a lot, you are asking Does the C++ standard allow a compiler to assume a bool can only have an internal numerical representation of '0' or '1' and use it in such a way? The...

View Article



Answer by Peter Cordes for Does the C++ standard allow for an uninitialized...

Yes, ISO C++ allows (but doesn't require) implementations to make this choice. But also note that ISO C++ allows a compiler to emit code that crashes on purpose (e.g. with an illegal instruction) if...

View Article

Answer by M.M for Does the C++ standard allow for an uninitialized bool to...

The function itself is correct, but in your test program, the statement that calls the function causes undefined behaviour by using the value of an uninitialized variable. The bug is in the calling...

View Article

Answer by Barmar for Does the C++ standard allow for an uninitialized bool to...

A bool is only allowed to hold the implementation-dependent values used internally for true and false, and the generated code can assume that it will only hold one of these two values. Typically, the...

View Article

Answer by rici for Does the C++ standard allow for an uninitialized bool to...

The compiler is allowed to assume that a boolean value passed as an argument is a valid boolean value (i.e. one which has been initialised or converted to true or false). The true value doesn't have to...

View Article


Does the C++ standard allow for an uninitialized bool to crash a program?

I know that an "undefined behaviour" in C++ can pretty much allow the compiler to do anything it wants. However, I had a crash that surprised me, as I assumed that the code was safe enough. In this...

View Article

Answer by Steve Summit for Does the C++ standard allow for an uninitialized...

Does the C++ standard allow a compiler to assume a bool can only have an internal numerical representation of '0' or '1' and use it in such a way?Yes indeed, and in case it's useful to anyone, here's...

View Article
Browsing latest articles
Browse All 7 View Live


Latest Images