This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: zero sized initializers with side effects discarded
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: "'Olivier Hainque'" <hainque at adacore dot com>,"'Daniel Berlin'" <dberlin at dberlin dot org>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Fri, 9 Sep 2005 14:36:39 +0100
- Subject: RE: zero sized initializers with side effects discarded
----Original Message----
>From: Olivier Hainque
>Sent: 09 September 2005 14:25
> You may have side effect from an initializer when setting a zero
> sized field.
>
> For instance (variant of gcc.c-torture/compile/zero-strct-4.c), compiled
> with GCC 3.4, the code below prints "returning raw_lock" as I would
> expect. It doesn't print anything when compiled with mainline because
> one_raw_spinlock is not called.
>
> #include <stdio.h>
>
> typedef struct {} raw_spinlock_t;
>
> typedef struct {
> raw_spinlock_t raw_lock;
> } spinlock_t;
>
>
> raw_spinlock_t one_raw_spinlock (void)
> {
> raw_spinlock_t raw_lock;
> printf ("returning raw_lock\n");
> return raw_lock;
> }
Surely returning the vaule of this uninitialised variable makes your code
invalid?
cheers,
DaveK
--
Can't think of a witty .sigline today....