[MINC-development] warning from volume_io/alloc.h
Claude LEPAGE
claude at bic.mni.mcgill.ca
Wed Dec 12 00:44:17 EST 2012
Hi,
I tried Sean's suggestion of the latter. Well... not so fun says the
compiler. My former way is much simpler to implement. Changing to
const char * would mean redefining VIO_STR (alias STRING) to be a
const char * instead of its current definition of char *. Lots of
prototypes to change everywhere (I'm too lazy to do it). :-)
I also tried const char * in /libsrc/ParseArgv.h and it compiles cleanly:
/*
* Structure used to specify how to handle argv options.
*/
typedef struct {
const char *key; /* The key string that flags the option in the
* argv array. */
int type; /* Indicates option type; see below. */
char *src; /* Value to be used in setting dst; usage
* depends on type. */
char *dst; /* Address of value to be modified; usage
* depends on type. */
const char *help; /* Documentation message describing this option. */
} ArgvInfo;
Claude
> >#define =5FALLOC=5FSOURCE=5FLINE , (char*)=5F=5FFILE=5F=5F, =
> =5F=5FLINE=5F=5F
> >#define =5FALLOC=5FSOURCE=5FLINE=5FARG=5FDEF , char filename[], int =
> line=5Fnumber
> >#define =5FALLOC=5FSOURCE=5FLINE=5FARGUMENTS , filename, line=5Fnumber
> >#define PRINT=5FALLOC=5FSOURCE=5FLINE \
> > print=5Falloc=5Fsource=5Fline( filename, line=5Fnumber );
> >#endif
> >
> >
> >Note the cast (char*) on =5F=5FFILE=5F=5F, which is consistent with the
> >definition on the next line char filename[]. By default, the compiler
> >assumes const char * and writes out a warning. Unless we change
> >=5FALLOC=5FSOURCE=5FLINE=5FARG=5FDEF to const char filename[]...
>
> The latter sounds preferable. Casting away const is a big enough code =
> smell to be listed in places like this:
>
> <https://www.securecoding.cert.org/confluence/display/seccode/EXP05-C.+Do+n=
> ot+cast+away+a+const+qualification>
>
> Cheers,
>
> --
> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> Sean McBride, B. Eng sean at rogue-research.com
> Rogue Research www.rogue-research.com
> Mac Software Developer Montr=E9al, Qu=E9bec, Canada
>
>
More information about the MINC-development
mailing list