This is the mail archive of the gcc@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]

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....


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