Tuesday, 15 June 2010

qt - What is VS C++ compiler supposed to do with this code? -



qt - What is VS C++ compiler supposed to do with this code? -

here reduced code snippet needed debug today.

i accidently typed this:

qimage myimage = loadimage(path); qimage scaledimage = myimage.scaled(100, 100); if (condition) { qimage scaledimage = scaledimage.mirrored(true, true); // *** crash *** }

instead of intendend code:

qimage myimage = loadimage(path); qimage scaledimage = myimage.scaled(100, 100); if (condition) { scaledimage = scaledimage.mirrored(true, true); // *** works fine *** }

i have expected flawed code either work expected or generate compiler error. crashed partition zero. why? can tell me compiler's point of view mistake?

the reason still there if cut down code.

this:

qimage myimage = loadimage(path); qimage scaledimage = myimage.scaled(100, 100); if (condition) { qimage scaledimage = scaledimage.mirrored(true, true); // *** crash *** }

has same error this:

qimage myimage = loadimage(path); qimage scaledimage = scaledimage.mirrored(true, true); // *** crash ***

because scaledimage on right side calling function on uninitialized object left side. undefined behavior.

c++ qt visual-studio-2013

No comments:

Post a Comment