[Bug c/57133] false const qualifier warning typedef

mikpe at it dot uu.se gcc-bugzilla@gcc.gnu.org
Wed May 1 11:38:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57133

--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2013-05-01 11:37:56 UTC ---
(In reply to comment #0)
> typedef char *type;
> 
> void f(const type t)
> {

This doesn't do what you think it does.  t is now a const variable of type
char*, not a variable of type const char*.  Observe:

> cat pr57133.c
typedef char *type;
void f(const type t) { t = 0; }
void g(const type t) { *t = 0; }
> gcc -Wall -S pr57133.c
pr57133.c: In function 'f':
pr57133.c:2:1: error: assignment of read-only parameter 't'

The warning in your main() is correct.



More information about the Gcc-bugs mailing list