linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* pointer indirection on the LHS of an assignment
@ 2006-10-07 13:12 Robert P. J. Day
  2006-10-07 22:53 ` Glynn Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Robert P. J. Day @ 2006-10-07 13:12 UTC (permalink / raw)
  To: C programming list


  sort of a combination of a C and gcc question but what's the rules
these days on the following (ripped from the linux kernel source, from
asm/semaphore.h)?

===
static inline void sema_init (struct semaphore *sem, int val)
{
/*
 *      *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
 *
 * i'd rather use the more flexible initialization above, but sadly
 * GCC 2.7.2.3 emits a bogus warning. EGCS doesn't. Oh well.
 */
        atomic_set(&sem->count, val);
        sem->sleepers = 0;
        init_waitqueue_head(&sem->wait);
}
===

  i recall that earlier compilers complained about that first example
of pointer indirection as the target of an assignment.  is that legal
these days?

rday

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: pointer indirection on the LHS of an assignment
  2006-10-07 13:12 pointer indirection on the LHS of an assignment Robert P. J. Day
@ 2006-10-07 22:53 ` Glynn Clements
  2006-10-08  6:53   ` Robert P. J. Day
  0 siblings, 1 reply; 4+ messages in thread
From: Glynn Clements @ 2006-10-07 22:53 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: C programming list


Robert P. J. Day wrote:

>   sort of a combination of a C and gcc question but what's the rules
> these days on the following (ripped from the linux kernel source, from
> asm/semaphore.h)?
> 
> ===
> static inline void sema_init (struct semaphore *sem, int val)
> {
> /*
>  *      *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
>  *
>  * i'd rather use the more flexible initialization above, but sadly
>  * GCC 2.7.2.3 emits a bogus warning. EGCS doesn't. Oh well.
>  */
>         atomic_set(&sem->count, val);
>         sem->sleepers = 0;
>         init_waitqueue_head(&sem->wait);
> }
> ===
> 
>   i recall that earlier compilers complained about that first example
> of pointer indirection as the target of an assignment.  is that legal
> these days?

The problem with the first example is that the __SEMAPHORE_INITIALIZER
macro uses C99 features, which probably aren't supported in gcc 2.7.x.

The LHS has nothing to do with it.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: pointer indirection on the LHS of an assignment
  2006-10-07 22:53 ` Glynn Clements
@ 2006-10-08  6:53   ` Robert P. J. Day
  2006-10-08 12:17     ` Glynn Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Robert P. J. Day @ 2006-10-08  6:53 UTC (permalink / raw)
  To: Glynn Clements; +Cc: C programming list

On Sat, 7 Oct 2006, Glynn Clements wrote:

>
> Robert P. J. Day wrote:
>
> >   sort of a combination of a C and gcc question but what's the rules
> > these days on the following (ripped from the linux kernel source, from
> > asm/semaphore.h)?
> >
> > ===
> > static inline void sema_init (struct semaphore *sem, int val)
> > {
> > /*
> >  *      *sem = (struct semaphore)__SEMAPHORE_INITIALIZER((*sem),val);
> >  *
> >  * i'd rather use the more flexible initialization above, but sadly
> >  * GCC 2.7.2.3 emits a bogus warning. EGCS doesn't. Oh well.
> >  */
> >         atomic_set(&sem->count, val);
> >         sem->sleepers = 0;
> >         init_waitqueue_head(&sem->wait);
> > }
> > ===
> >
> >   i recall that earlier compilers complained about that first example
> > of pointer indirection as the target of an assignment.  is that legal
> > these days?
>
> The problem with the first example is that the
> __SEMAPHORE_INITIALIZER macro uses C99 features, which probably
> aren't supported in gcc 2.7.x.
>
> The LHS has nothing to do with it.

ah, sorry, i didn't look closely enough.  so if one could count on a
C99-compilant compiler being available, then the first form would be
perfectly acceptable?  thanks.

rday

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: pointer indirection on the LHS of an assignment
  2006-10-08  6:53   ` Robert P. J. Day
@ 2006-10-08 12:17     ` Glynn Clements
  0 siblings, 0 replies; 4+ messages in thread
From: Glynn Clements @ 2006-10-08 12:17 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: C programming list


Robert P. J. Day wrote:

> > The problem with the first example is that the
> > __SEMAPHORE_INITIALIZER macro uses C99 features, which probably
> > aren't supported in gcc 2.7.x.
> >
> > The LHS has nothing to do with it.
> 
> ah, sorry, i didn't look closely enough.  so if one could count on a
> C99-compilant compiler being available, then the first form would be
> perfectly acceptable?  thanks.

Yes.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-10-08 12:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-07 13:12 pointer indirection on the LHS of an assignment Robert P. J. Day
2006-10-07 22:53 ` Glynn Clements
2006-10-08  6:53   ` Robert P. J. Day
2006-10-08 12:17     ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).