char vs char*

Todd Freed todd.freed@gmail.com
Wed Jun 16 06:16:00 GMT 2010


On 06/15/2010 11:27 AM, Ian Lance Taylor wrote:
> 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
>    

Thanks for the explanation

-Todd



More information about the Gcc-help mailing list