[gmx-developers] A question about 'enum' datatype in Gromacs, ask for help
Szilárd Páll
szilard.pall at cbr.su.se
Fri Mar 11 16:24:42 CET 2011
Correct, the enum identifier is optional; from the C99 specs
(http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf):
6.7.2.2 Enumeration specifiers
Syntax:
enum-specifier:
enum identifier_opt { enumerator-list }
enum identifier_opt { enumerator-list , }
enum identifier
enumerator-list:
enumerator
enumerator-list , enumerator
enumerator:
enumeration-constant
enumeration-constant = constant-expression
However, I would argue that it is a good practice to name the enum-s.
A simple practical advantage is that one could refer to the
enumeration by using its name which comes quite handy when two types
have to be kept in sync and comments at the respective definitions
should indicate this.
> In C++, however, the tag is not optional as far as I know. But please do
> correct me if I'm wrong.
Correct.
--
Szilárd
On Fri, Mar 11, 2011 at 3:52 PM, Erik Marklund <erikm at xray.bmc.uu.se> wrote:
> In C++, however, the tag is not optional as far as I know. But please do
> correct me if I'm wrong.
>
> Erik Marklund skrev 2011-03-11 15.46:
>>
>> No, the syntax is:
>>
>> enum [ tag ] { sun, mon,... };
>>
>> where the tag is optional.
>>
>> Yukun Wang skrev 2011-03-11 15.25:
>>>
>>> Hi,
>>> I am recently reading the GMX src-code for some need. I notice there are
>>> many 'enum' typy defination in the 'enums.h' file. They are just like this:
>>>
>>> ...
>>> enum {
>>> epbcXYZ, epbcNONE, epbcXY, epbcSCREW, epbcNR
>>> };
>>>
>>> enum {
>>> etcNO, etcBERENDSEN, etcNOSEHOOVER, etcYES, etcANDERSEN,
>>> etcANDERSENINTERVAL, etcVRESCALE, etcNR
>>> };
>>> ...
>>>
>>> However in the standard C, enum type should be defined like ' enum
>>> enumtypename { Sum, Mon,...,Sat } enumname1 ' .
>>> For the GMX code above I don't understand how it is work?
>>>
>>> I also notice there is a note ' /* note: these enums should correspond to
>>> the names in gmxlib/names.c */' ,
>>> ...
>>> const char *epbc_names[epbcNR+1]=
>>> {
>>> "xyz", "no", "xy", "screw", NULL
>>> };
>>>
>>> const char *ens_names[ensNR+1]=
>>> {
>>> "Grid","Simple", NULL
>>> };
>>> ...
>>> I just don't know how the two files are matched automatically. Is any
>>> suggestion about this?
>>>
>>>
>>>
>>>
>>
>>
>
>
> --
> -----------------------------------------------
> Erik Marklund, PhD student
> 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://folding.bmc.uu.se/
>
> --
> 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