[ub] Undefined behaviour from uninitialised variables
Nevin Liber
nevin at eviloverlord.com
Thu Oct 31 18:29:41 CET 2013
On 31 October 2013 08:31, Peter Sommerlad <peter.sommerlad at hsr.ch> wrote:
> Chris,
>
> I teach my C++11 students to always use curly braces when defining a
> variable or assign an auto variable from an expression. This way it is
> guaranteed to be initialized. Any code that doesn't use them is easy to
> spot.
>
In practice I've found this helps make the bugs repeatable at run time, but
rarely addresses the underlying problem. People ought to think about how
they want to initialize stuff.
And then there are annoying cases where that just doesn't work:
struct S
{
S() : b{} () // does not do what you think it should do
std::atomic<bool> b;
};
Like the pro-ub arguments, just initializing something makes it much harder
to analyze the code to find bugs.
--
Nevin ":-)" Liber <mailto:nevin at eviloverlord.com> (847) 691-1404
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open-std.org/pipermail/ub/attachments/20131031/598913f8/attachment.html
More information about the ub
mailing list