This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

"initializer element is not constant" problem


Hi all,

While trying to complie linux kernel 2.4.16 using gcc 3.1, I encountered
numerous "initializer element is not constant" errors (target is sh-linux).
First error is reported in linux/kernel/printk.c.
I extracted relative codes from printk.c and include files as follows.

-----
typedef struct { } spinlock_t;

struct list_head {
        struct list_head *next, *prev;
};

struct __wait_queue_head {
        spinlock_t lock;
        struct list_head task_list;
};
typedef struct __wait_queue_head wait_queue_head_t;

wait_queue_head_t log_wait = {
  lock: (spinlock_t) {  }, \
  task_list: { &(log_wait.task_list), &(log_wait.task_list) },
 };
-----
$ sh-linux-gcc -c const_error.c
const_error.c:14: initializer element is not constant
const_error.c:14: (near initialization for `log_wait.lock')
const_error.c:16: initializer element is not constant

As you can see, the code will be broken at line 14. But, when the cast
operator (spinlock_t) is removed, compilation will succeed.

-----
typedef struct { } spinlock_t;

struct list_head {
        struct list_head *next, *prev;
};

struct __wait_queue_head {
        spinlock_t lock;
        struct list_head task_list;
};
typedef struct __wait_queue_head wait_queue_head_t;

wait_queue_head_t log_wait = {
  lock: {  }, \
  task_list: { &(log_wait.task_list), &(log_wait.task_list) },
 };
-----
$ sh-linux-gcc -c const_error.c ; echo $?
0

I can't figure out whether this is an error or gcc bug.
I would appreciate your comments or suggestions.
Thank you.

Wataru Nishida


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]