Code Question in FAT Filesystem

Joel Sherrill joel.sherrill at OARcorp.com
Mon Aug 23 18:44:12 UTC 2010


On 08/23/2010 01:41 PM, Eric Norum wrote:
> Are you sure that's illegal in C++?
>    
I was just trusting a hit from Google.

So you think changing it to const char * would be cool?
> With this little file:
> =======================================
> int main()
> {
>      const char *const foo = "abc";
>      const char *bar = "abc";
>      char *const bletch = "abc";
>
>      foo = "hi";
>      *foo = 'x';
>      bar = "hi";
>      *bar = 'x';
>      bletch = "hi";
>      *bletch = 'x';
>      return 0;
> }
> =======================================
> Compiling as a C program (gcc) yields:
> con.c: In function 'main':
> con.c:7: error: assignment of read-only variable 'foo'
> con.c:8: error: assignment of read-only location
> con.c:10: error: assignment of read-only location
> con.c:11: error: assignment of read-only variable 'bletch'
>
> Compiling as a C++ progtram(g++) yields:
> con.cc: In function 'int main()':
> con.cc:5: warning: deprecated conversion from string constant to 'char*'
> con.cc:7: error: assignment of read-only variable 'foo'
> con.cc:8: error: assignment of read-only location
> con.cc:10: error: assignment of read-only location
> con.cc:11: error: assignment of read-only variable 'bletch'
> con.cc:11: warning: deprecated conversion from string constant to 'char*'
>
>
> Looks like the same set of errors from both languages.
>
>    


-- 
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





More information about the users mailing list