[GRASS5] ANSIfication of GRASS 6.1-CVS functions

Glynn Clements glynn at gclements.plus.com
Mon Jan 2 12:35:40 EST 2006


Markus Neteler wrote:

> I have submitting updated function declarations
> to CVS to migrate old K&R style to ANSI style. About
> 800 functions in 230 files are affected.
> 
> This work was only possible thanks to the efforts
> of Prof Giulio Antoniol (École Polytechnique, Montreal,
> Canada) who analyzed the 6.1-CVS code and wrote a PERL
> script for me/us to auto-convert the function
> declarations.

Is there a problem with the "protoize" utility (from gcc)?

> I am submitting things only after inspection.
> The list of changes (CVS diffs) is available at:
> http://grass.itc.it/pipermail/grass-commit/2006-January/date.html#end
> 
> My gcc flags for compilation are (pretty restrictive):
>   MYCFLAGS="-g -Wall -Werror-implicit-function-declaration -fno-common"
>   MYCXXFLAGS="-g -Wall"
>   CFLAGS="$MYCFLAGS" CXXFLAGS="$MYCXXFLAGS" ./configure ...
> 
> A few doubts I have which I would like to discuss here
> before submitting:
> 
> ####################
> I fixed (hopefully correctly) the 'wext()' definition
> and calls in
> 
>  lib/cdhc/as181.c

Note that, for function arguments, there is no semantic difference
between "double x[]" and "double *x".

Personally, I always use the latter as what is being passed is a
pointer, but some people like to use the different syntaxes to
indicate whether the pointer points to a single value (*x) or to
multiple values (x[]).

> ####################
> Then a conflict in lib/gis/:
> 
> definition in gisdefs.h:
> 
> /* index.c */
> char *G_index(char *, int);
> char *G_rindex(char *, int);
> 
> definition in index.c:
> 
> char *
> G_index  (register char *str, register char delim)
> 
> char *
> G_rindex  (register char *str, register char delim)

Using "register" in argument lists is meaningless. Whether or not a
register is used is determined by the calling convention.

Linux/x86/gcc uses the stack by default; you can force the use of a
register using the "regparm" attribute, but that's seldom a good idea.

For local variables, it's almost always preferable to let the compiler
figure out when to use a register (and most modern compilers will just
ignore "register" specifiers).

> ####################
> another one in lib/gis
> 
> /* unctrl.c */
> char *G_unctrl(int);
> 
> definition in unctrl.c
> char *G_unctrl(unsigned char c);

Change the implementation to match the declaration in gisdefs.h. The
K&R version will expect an int to have been passed, as that's the
smallest integral type that K&R allows.

> ####################
> imagery/open.c
> 
> static error  (char *group, char *file, char *msga, char *msgb)
> 
> The compiler complains about absent return type:
> open.c:12: warning: return type defaults to `int'
> open.c: In function `error':
> open.c:17: warning: control reaches end of non-void function

Change it to "static void error(...)".

> ####################
> Unrelated, I found that by chance:
> 
> bartok:gis[6941.292] grep 'floor()\|ceil()' *
> align_window.c:    double floor(), ceil();
> color_range.c:    double floor(), ceil();
> 
> I guess that it is no good idea to have it
> defined, right?

Use "#include <math.h>" to get the prototypes.

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




More information about the grass-dev mailing list