[gmx-developers] uninitialized data
Erik Marklund
erikm at xray.bmc.uu.se
Wed Apr 22 10:41:46 CEST 2009
Erik Lindahl skrev:
>
> On Apr 21, 2009, at 9:00 PM, David van der Spoel wrote:
>
>> Alexander Herz wrote:
>>> of course it must be
>>> memset(fr,0,sizeof(t_forcerec)); as fr is a pointer
>>
>> snew does this.
>
> In practice you're right, but:
>
> 1) It is incredibly bad coding habit to rely on the behaviour of
> memory allocation for initializing objects.
>
> 2) Formally it is even wrong (but so is memset). There is nothing in
> the ISO C standard that *requires* NULL to be represented by numerical 0.
>
> Cheers,
>
> Erik
I second that. There are for instance environment variables that makes
the malloc-family of functions write non-zero bytes to (de)allocated
memory. Although it's convenient to rely on eg. snew() I bet one can
avoid some pretty hard-to-find mysterious bugs on certain systems by
explicitly initializing objects whenever initialization is critical. The
best time to do it is when implementing things in the first place;
honsetly, how often does one go back to polish the code one wrote n
months ago just to make it more compliant to eg. the C standard?
My 2 cents.
/Erik
>
> _______________________________________________
> gmx-developers mailing list
> gmx-developers at gromacs.org
> http://www.gromacs.org/mailman/listinfo/gmx-developers
> Please don't post (un)subscribe requests to the list. Use thewww
> interface or send it to gmx-developers-request at gromacs.org.
--
-----------------------------------------------
Erik Marklund, PhD student
Laboratory of Molecular Biophysics,
Dept. of Cell and Molecular Biology, Uppsala University.
Husargatan 3, Box 596, 75124 Uppsala, Sweden
phone: +46 18 471 4537 fax: +46 18 511 755
erikm at xray.bmc.uu.se http://xray.bmc.uu.se/molbiophys
More information about the gromacs.org_gmx-developers
mailing list