19th June 22:04
Impossible Leak realloc
It's not legal C++ either, but with a fair number of adjustments...
There is no such header in C or in C++.
In C++, at least, main *must* return an int. In C it normally returns
an int as well, but I think the C standard allows a conformant compiler
to accept a void return as an extension. As an extension -- "void main"
is not standard conforming C.
This line shouldn't pass a C complier, although it is legal C++. If you
struct st_Test* pst_Test ;
it would be legal in both languages.
You don't need the test -- realloc is guaranteed to work correctly if
passed a NULL pointer.
I'm not sure what you are trying to do here, but you initialize the
pVoid element to a possibly invalid value, both in C and in C++.
If you want the equivalent of zero initialization, the standard idiom
would be to define a static object, and assign from it:
static struct st_Test zeroInitialized ;
pst_Test[ i ] = zeroInitialized ;
This line contains undefined behavior. Both in C and in C++.
Of course, since you never free any memory, it is normal that you have a
memory leak. The code returns from main, and the only pointer to your
structures disappears, so any checker will call it a leak.
James Kanze GABI Software mailto:email@example.com
Conseils en informatique oriente objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, Tl. : +33 (0)1 30 23 45 16
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]