[parisc-linux] possible gcc-3.2 bug?

John David Anglin dave@hiauly1.hia.nrc.ca
Tue, 15 Oct 2002 17:37:47 -0400 (EDT)


> The following piece of code compiles with gcc-3.0 but not with
> gcc-3.2... is this a gcc bug? or is the code broken?

I would say the later.

> tausq@a500:~$ gcc-3.2 -c t.c
> t.c: In function `foo':
> t.c:12: initializer element is not constant
> 
> (it's a simplified example of some code from the parisc-linux kernel)
> 
> ---------------------8<-----------------------
> /* compile with gcc -c foo.c */
> 
> typedef struct {
>         volatile unsigned int lock;
> } spinlock_t;
> 
> typedef struct {
>         spinlock_t lock;
>         volatile int counter;
> } rwlock_t;
> 
> void foo(void)
> {
>         static rwlock_t x = (rwlock_t) { (spinlock_t) { 1 }, 0 };
> }

Except for sizeof, cast operators in initializers for static variables
can only be used to convert arithmetic types.  GCC allows non-constant
initializers for automatic variables.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)