[GRASS-dev] Are such construction/declaration allowed for GRASS ??

Hi
Can I use in module prepared for GRASS such constructions:

typedef enum {
    AND, /* & */
    OR, /* | */
    NOT, /* ~ */
    IS, /* = */
    THEN, /* : */
    LBRC, /* ( */
    RBRC, /* ) */
    START, /* { */
    STOP, /* } */
    MAP, /* mapname */
    VAR, /* variable name */
    size /* number of tokens */
} tokens;

char parseTab [size][size] = { /* parser table definition is here */
    };

I mean type enum and enum size variable to initialize table. It compiles on gcc 4.3 but, as I know GRASS has restriction and I'm not sure if such is fully allowed.

thanks for answer
Jarek

Jarosław Jasiewicz wrote:

Can I use in module prepared for GRASS such constructions:

typedef enum {
    AND, /* & */
    OR, /* | */
    NOT, /* ~ */
    IS, /* = */
    THEN, /* : */
    LBRC, /* ( */
    RBRC, /* ) */
    START, /* { */
    STOP, /* } */
    MAP, /* mapname */
    VAR, /* variable name */
    size /* number of tokens */
} tokens;

char parseTab [size][size] = { /* parser table definition is here */
    };

I mean type enum and enum size variable to initialize table. It compiles
on gcc 4.3 but, as I know GRASS has restriction and I'm not sure if such
is fully allowed.

In general, if it's valid C89 (use "gcc -std=c89 ..." to check), then
it's fine. Any use of gcc extensions or C99-specific features must be
conditional, with a fallback if those features aren't available.
Similarly, use of functions which aren't specified by C89 should be
conditionalised (non-C89 functions which are specified by POSIX are
okay provided that they're available on Linux, Windows and MacOSX).

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements pisze:

Jaros³aw Jasiewicz wrote:

Can I use in module prepared for GRASS such constructions:

typedef enum {
    AND, /* & */
    OR, /* | */
    NOT, /* ~ */
    IS, /* = */
    THEN, /* : */
    LBRC, /* ( */
    RBRC, /* ) */
    START, /* { */
    STOP, /* } */
    MAP, /* mapname */
    VAR, /* variable name */
    size /* number of tokens */
} tokens;

char parseTab [size][size] = { /* parser table definition is here */
    };

I mean type enum and enum size variable to initialize table. It compiles on gcc 4.3 but, as I know GRASS has restriction and I'm not sure if such is fully allowed.
    
In general, if it's valid C89 (use "gcc -std=c89 ..." to check), then
it's fine. Any use of gcc extensions or C99-specific features must be
conditional, with a fallback if those features aren't available. Similarly, use of functions which aren't specified by C89 should be
conditionalised (non-C89 functions which are specified by POSIX are
okay provided that they're available on Linux, Windows and MacOSX).

Ok, thanks Glynn. It means I shoud be OK, but I didn't find typedef enum ... in any fo GRASS code, so I asked.
Jarek.

Hi,

2010/3/13 Jarek Jasiewicz <jarekj@amu.edu.pl>:

[...]

Ok, thanks Glynn. It means I shoud be OK, but I didn't find typedef enum ...
in any fo GRASS code, so I asked.

see e.g.

http://trac.osgeo.org/grass/browser/grass/trunk/db/drivers/postgres/globals.h#L25

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa