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

Szilárd Páll szilard.pall at cbr.su.se
Wed Apr 11 22:01:02 CEST 2012


On Wed, Apr 11, 2012 at 4:14 PM, Roland Schulz <roland at utk.edu> wrote:
>
>
> On Wed, Apr 11, 2012 at 9:50 AM, Szilárd Páll <szilard.pall at cbr.su.se>
> wrote:
>>
>> On Wed, Apr 11, 2012 at 3:16 PM, Peter Kasson <kasson at stanford.edu> wrote:
>> >> 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
>>
>> That's C++ and we're not there yet. For 4.6 IMO it makes sense to
>> clarify code by replacing "x/10.0" with "x/A2NM". In fact, this will
>> help with the transition to constants later.
>
>
> What's wrong with using "const" constants in C?

Indeed, nothing is wrong with it, I was referring to the fact that the
link is the Google C++ Style Guide.

If we are already at it, it's worth noting a few things, but let me
get back to the original thread.

--
Szilárd


> Roland
>
>>
>>
>> --
>> Szilárd
>>
>>
>>
>> > --
>> > 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.
>> --
>> 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.
>>
>>
>>
>>
>
>
>
> --
> ORNL/UT Center for Molecular Biophysics cmb.ornl.gov
> 865-241-1537, ORNL PO BOX 2008 MS6309
>
> --
> 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.



More information about the gromacs.org_gmx-developers mailing list