c99 and pthread.h

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

c99 and pthread.h

Thorsten Kukuk

Hi,

with current glibc CVS I get an error message if I use pthread.h,
mutex initializer and compile with -std=c99:

kukuk@firun:~/tmp> gcc -std=c99 pthread.h.c
pthread.h.c:3: error: extra brace group at end of initializer
pthread.h.c:3: error: (near initialization for 'plugin_mutex.__data')
pthread.h.c:3: warning: excess elements in struct initializer
pthread.h.c:3: warning: (near initialization for 'plugin_mutex.__data')

test program:

#include <pthread.h>

static pthread_mutex_t plugin_mutex = PTHREAD_MUTEX_INITIALIZER;

int
main ()
{
  return 0;
}



--
Thorsten Kukuk         http://www.suse.de/~kukuk/      [hidden email]
SUSE LINUX Products GmbH       Maxfeldstr. 5       D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

Reply | Threaded
Open this post in threaded view
|

Re: c99 and pthread.h

Andreas Jaeger
Thorsten Kukuk <[hidden email]> writes:

> Hi,
>
> with current glibc CVS I get an error message if I use pthread.h,

This happens on i386 and s390 - AFAIK it does not happen on 64-bit
systems,

Andreas
--
 Andreas Jaeger, [hidden email], http://www.suse.de/~aj
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

attachment0 (194 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: c99 and pthread.h

Ulrich Drepper
In reply to this post by Thorsten Kukuk
Thorsten Kukuk wrote:
> with current glibc CVS I get an error message if I use pthread.h,
> mutex initializer and compile with -std=c99:

gcc ignores the transparent union in c99 mode.  This does not look
right.  You might want to ask the gcc people instead.

--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


signature.asc (259 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: c99 and pthread.h

Jakub Jelinek
On Mon, Jan 09, 2006 at 12:10:43PM -0800, Ulrich Drepper wrote:
> Thorsten Kukuk wrote:
> > with current glibc CVS I get an error message if I use pthread.h,
> > mutex initializer and compile with -std=c99:
>
> gcc ignores the transparent union in c99 mode.  This does not look
> right.  You might want to ask the gcc people instead.

But anonymous unions aren't ISO C99 nor ISO C89, which is why GCC complains.
I have tested __extension__ shuts this up, but that lefts out non-GCC
compilers.  So we can use:

    __extension__ union
    {
      int __spins;
      struct __pthread_mutex_s *__next;
    };

if we don't care about non-GCC (verified this shuts the errors/warnings
up in both -std=c89 and -std=c99 mode), or e.g.

    __extension__ union
    {
      int __spins;
      struct __pthread_mutex_s *__next;
    }
# if __GNUC_PREREQ (3,2)
      ;
# else
      s;
# endif

(3.2 chosen arbitrarily, would need to see when exactly was anonymous
union support added), or

    __extension__ union
    {
      int __spins;
      struct __pthread_mutex_s *__next;
    }
# ifdef _LIBC
      ;
# else
      s;
# endif

        Jakub

Reply | Threaded
Open this post in threaded view
|

Re: c99 and pthread.h

Roland McGrath
In reply to this post by Thorsten Kukuk
This should be fixed (and tested) now.  (Compilers not supporting
__extension__ are SOL.)