|
From: André W. <Woe...@on...> - 2009-05-12 16:33:34
Attachments:
test.cpp
|
Hi, I'm using Valgrind 3.4.1 and I wonder why I don't get a warning for the std::swap() call in the attached example. I get one in printf(). Is this a bug? Cheers, André |
|
From: Colin M. <col...@pi...> - 2009-05-12 16:44:37
|
André Wöbbeking wrote: > Hi, > > I'm using Valgrind 3.4.1 and I wonder why I don't get a warning for the > std::swap() call in the attached example. I get one in printf(). Is this > a bug? > > > Cheers, > André > > ------------------------------------------------------------------------ André, Valgrind only reports when an unused variable is used for flow-control (or, hopefuly I/O). Swapping doesn't trigger the alert. This is because, in C, structures can legitimately have uninitialised areas due to nested unions or padding. printf() uses flow-control to decide how many characters to print. HTH, Colin S. Miller |
|
From: Nicholas N. <n.n...@gm...> - 2009-05-12 22:18:17
|
On Wed, May 13, 2009 at 2:43 AM, Colin Miller <col...@pi...> wrote: > André Wöbbeking wrote: > > Valgrind only reports when an unused variable is used for flow-control > (or, hopefuly I/O). > > Swapping doesn't trigger the alert. This is because, in C, structures > can legitimately have > uninitialised areas due to nested unions or padding. There's more on this in the manual. And this blog post discusses it in even more detail: http://blog.mozilla.com/nnethercote/2009/02/27/eliminating-undefined-values-with-valgrind-the-easy-way/ Nick |
|
From: André W. <Woe...@on...> - 2009-05-13 14:22:58
|
On Wednesday 13 May 2009, Nicholas Nethercote wrote: > On Wed, May 13, 2009 at 2:43 AM, Colin Miller <col...@pi...> wrote: > > André Wöbbeking wrote: > > > > Valgrind only reports when an unused variable is used for > > flow-control (or, hopefuly I/O). > > > > Swapping doesn't trigger the alert. This is because, in C, > > structures can legitimately have > > uninitialised areas due to nested unions or padding. > > There's more on this in the manual. And this blog post discusses it > in even more detail: > > http://blog.mozilla.com/nnethercote/2009/02/27/eliminating-undefined- >values-with-valgrind-the-easy-way/ Thanks. Now back to my problem. The original code has double instead of int (I just tried both types to be sure and forgot to change back) and on MSVC std::swap() of uninitialised doubles triggers a floating point exception (if enabled) as MSVC uses the FPU. I was really surprised that the code crashes on WIndows as it runs fine under valgrind on Linux. Cheers, André |
|
From: Dallman, J. <joh...@si...> - 2009-05-13 14:53:39
|
> Now back to my problem. The original code has double instead of int (I > just tried both types to be sure and forgot to change back) and on MSVC > std::swap() of uninitialised doubles triggers a floating point > exception (if enabled) as MSVC uses the FPU. > > I was really surprised that the code crashes on Windows as it runs fine > under valgrind on Linux. This is a long-established quirk of Microsoft's compilers. They assume, rather more deeply than most people, that floating point traps will be turned off. -- John Dallman Parasolid Porting Engineer |