Code Question in FAT Filesystem

Somervill, Kevin M. (LARC-D203) kevin.m.somervill at nasa.gov
Mon Aug 23 19:35:01 UTC 2010


I think the issue is the "const char const" that Joel originally posted.  The declaration "const char * const foo" is not the same as "const char const * foo".  In the latter, I believe both const qualifiers are associated with the char.  It looks like this format is left over from K&R C, but "const char *" and "char const *" seem to be equivalent.  Also, gcc will allow you to use as many const qualifiers as you like (eg. "const const const char stupid;" will compile using gcc but not g++).

>From the original email, you probably should swap the second const and the * to read "const char * const" so that neither the variable (MSDOS_DOT_NAME) nor the location (*MSDOS_DOT_NAME) can be changed. Perhaps like:

msdos.h:extern const char * const MSDOS_DOT_NAME;    /* ".", padded to MSDOS_NAME chars */ 

IMO.

./ks

| -----Original Message-----
| From: rtems-users-bounces at rtems.org [mailto:rtems-users-bounces at rtems.org] On
| Behalf Of Eric Norum
| Sent: Monday, August 23, 2010 2:30 PM
| To: Joel Sherrill
| Cc: rtems-users at rtems.org
| Subject: Re: Code Question in FAT Filesystem
| 
| I'm no expert on C++, but for C at least, I don't see any type qualifier being
| specified more than once:
| 	const char *const foo
| declares foo to be a constant pointer to constant character(s)
| 
| This is different than
| 	const *bar
| which declares bar as a mutable pointer to constant character(s)
| 
| or
| 	char *const bletch
| which declares bletch as a constant pointer to mutable character(s)
| 
| So, with these declarations:
| 	1) bletch could never appear as an lvalue, but *bletch could
| 	2) *bar could never appear as an lvalue, but bar could
| 	2) foo could never appear as an lvalue nor could *foo appear as an
| lvalue
| 
| FWIW.
| 
| On Aug 23, 2010, at 11:20 AM, Joel Sherrill wrote:
| 
| > Hi,
| >
| > I came across this while trying to review
| > Coverity output.
| >
| > [joel at iceland dosfs]$ grep "const char const" *
| > msdos.h:extern const char const* MSDOS_DOT_NAME;    /* ".", padded to
| MSDOS_NAME chars */
| > msdos.h:extern const char const* MSDOS_DOTDOT_NAME; /* ".", padded to
| MSDOS_NAME chars */
| > msdos_misc.c:const char const* MSDOS_DOT_NAME    = ".          ";
| > msdos_misc.c:const char const* MSDOS_DOTDOT_NAME = "..         ";
| >
| > My understanding is that this is legal in C99 and
| > illegal in C++.
| >
| > Coverity complains it is ...
| >
| > *dupl_type_qualifier*: type qualifier specified more than once
| >
| >
| > Would it be OK to change these to "const char *MSDOS_DOT_"?
| >
| > --
| > Joel Sherrill, Ph.D.             Director of Research&  Development
| > joel.sherrill at OARcorp.com        On-Line Applications Research
| > Ask me about RTEMS: a free RTOS  Huntsville AL 35805
| >   Support Available             (256) 722-9985
| >
| >
| > _______________________________________________
| > rtems-users mailing list
| > rtems-users at rtems.org
| > http://www.rtems.org/mailman/listinfo/rtems-users
| 
| --
| Eric Norum
| wenorum at lbl.gov
| 
| 
| _______________________________________________
| rtems-users mailing list
| rtems-users at rtems.org
| http://www.rtems.org/mailman/listinfo/rtems-users




More information about the users mailing list