[gmx-developers] Re: gmx-developers Digest, Vol 96, Issue 16

Erik Marklund erikm at xray.bmc.uu.se
Wed Apr 11 15:29:49 CEST 2012


11 apr 2012 kl. 15.16 skrev Peter Kasson:

>> Date: Wed, 11 Apr 2012 14:33:09 +0200
>> From: Erik Marklund <erikm at xray.bmc.uu.se>
>> Subject: Re: [gmx-developers] Coordinate scaling in pdbio.c
> [...]
>>>>>>> What happened to A2NM and NM2A?
>>>>>>> In my (4.0.5, yes that is very old) includes/physics.h I still see:
>>>>>>> 
>>>>>>> #define A2NM (ANGSTROM/NANO) /* NANO */
>>>>>>> #define NM2A (NANO/ANGSTROM) /* 10.0 */
>>>>>>> 
>>>>>>> Why aren't these still used for that?
>>>>>>> 
>>>>>>> 
>>>>>> At some stage macros were removed from the code, even though these seem rather harmless. I agree that it is confusing to hard code these numbers. If we cannot use macro's like this we should probably replace them by
>>>>>> static const real ANGSTROM=1e-10;
>>>>>> static const real NANO=1e-9;
>>>>>> 
>>>>>> etc.
>>>>>> 
>>>>>> Comments?
>>>>> 
>>>>> include/physics.h still has these macros. IMO, hard-coded constants are a greater evil than macros to prevent that, though I expect we will transition to const values at some stage soon.
>>>> 
>>>> But are these the kind of macros we want to avoid? Aren't function-like macros the ones to kill in the first place?
>>>  They're taking no parameters, so they're hardly function-like. The code fragments above are compiled into constants by the pre-processor. A macro that is used as
>>> 
>>> dist_in_nm = dist_in_angstrom * A2NM;
>>> 
>>> is much less evil than a macro
>>> 
>>> dist_in_nm = A2NM(dist_in_angstrom);
>> 
>> My point exactly. I'm just not seeing the harm in using macros in cases like these.
> 
> Consts are preferred (not #defines but actual consts).
> 
> http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Preprocessor_Macros

Thanks. Ok, I have no wish defending macros in absurdum, but I still think that these macros are pretty harmless, except perhaps that the names A2NM and NM2A are potentially non-unique.

> --
> gmx-developers mailing list
> gmx-developers at gromacs.org
> http://lists.gromacs.org/mailman/listinfo/gmx-developers
> Please don't post (un)subscribe requests to the list. Use the
> www interface or send it to gmx-developers-request at gromacs.org.

-----------------------------------------------
Erik Marklund, PhD
Dept. of Cell and Molecular Biology, Uppsala University.
Husargatan 3, Box 596,    75124 Uppsala, Sweden
phone:    +46 18 471 6688        fax: +46 18 511 755
erikm at xray.bmc.uu.se
http://www2.icm.uu.se/molbio/elflab/index.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.sys.kth.se/pipermail/gromacs.org_gmx-developers/attachments/20120411/1f08eb29/attachment.html>


More information about the gromacs.org_gmx-developers mailing list