This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: char vs char*
- From: Ian Lance Taylor <iant at google dot com>
- To: Todd Freed <todd dot freed at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 15 Jun 2010 10:27:04 -0700
- Subject: Re: char vs char*
- References: <4C166E0C.3020208@gmail.com>
Todd Freed <todd.freed@gmail.com> writes:
> I don't know if this is a bug, but I suspect that it is.
>
> Consider the following two declarations, which compile fine:
>
> 1 static char __attribute__((weakref("LNU__strmats__LNU")))
> strmats(char* s, char* m, int* l, unsigned int options)
> __attribute__((nonnull));
> 2 static char* __attribute__((weakref("LNU__strmat__LNU")))
> strmat(char* s, char* m, int* l, unsigned int options)
> __attribute__((nonnull));
>
> Then, if I move the 'static' keyword, like so:
>
> 1 char static __attribute__((weakref("LNU__strmats__LNU")))
> strmats(char* s, char* m, int* l, unsigned int options)
> __attribute__((nonnull));
> 2 char* static __attribute__((weakref("LNU__strmat__LNU")))
> strmat(char* s, char* m, int* l, unsigned int options)
> __attribute__((nonnull));
>
> The 1st declaration still compiles, but the 2nd one fails like this:
>
> error.c:1: error: expected identifier or '(' before 'static'
This is standard C behaviour. Storage specifiers and type specifiers
may occur in any order. However, the '*' is a type declarator. A
type declarator is associated with a specific name being declared.
Type declarators must follow storage specifiers.
In other words, the failing example above fails for the same reason
that
char *a, b;
declares a to have type "char*" and b to have type "char".
Ian