|
From: Evan L. <sa2...@cy...> - 2007-08-07 16:24:26
|
I have a problem with some C++ code when using a long double type. A long double is reported as 16 bytes on this system, but Valgrind reports an error if I set a char pointer to the start of the long double, and then try to read 16 bytes from it. The problem seems to be straightforward, and is that Valgrind is smart enough to know that a long double is actually 10 bytes, rather than 16 bytes, and it's reporting the top bytes as uninitialised (see http://osdir.com/ml/debugging.valgrind/2005-08/msg00376.html). Question: is there a smart way to get rid of these error messages? I have a lot of templated code that deals with arbitrary floating-point types, and it relies on 'sizeof' to tell it how big the type is. 'sizeof' tells me that a long double is 16 bytes, so I copy around and manipulate 16-byte quantities. I can get rid of the error messages by assuming that long doubles are actually 80 bits, and not 128 bits, but I'd rather not hard-wire this assumption into the code. Initialising an area of memory and then copying the long doubles into it doesn't work: Valgrind still reports an error, because the copy in of the long double still sets the top 6 bytes to uninitialised data. Any ideas? How does Valgrind know that a long double is 80 bits anyway? Thanks - Evan |