[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] pointers to static functions inside a static table
From: |
Aharon Robbins |
Subject: |
Re: [Tinycc-devel] pointers to static functions inside a static table |
Date: |
Thu, 19 May 2011 16:39:22 +0300 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Hi. Thanks for the note.
> From: "Thomas Preud'homme" <address@hidden>
> To: address@hidden
> Subject: Re: [Tinycc-devel] pointers to static functions inside a static table
> Date: Wed, 18 May 2011 22:57:55 +0200
> Cc: Aharon Robbins <address@hidden>
>
> Le vendredi 27 ao?t 2010 12:47:35, Aharon Robbins a ?crit :
> > Hi. I've reported this before, but here is a small test case:
> >
> > $ cat foo.c
> > #include <stdio.h>
> >
> > static void func();
> >
> > int main(int argc, char **argv)
> > {
> > static struct s {
> > void (*elem)();
> > } t[] = {
> > { func } /* tcc requires these braces! */
> > };
> >
> > printf("func is %p, t[0].func is %p\n", func, t[0].elem);
> > return 0;
> > }
> >
> > static void func()
> > {
> > int x = 1;
> > x++;
> > }
> >
> > $ gcc foo.c ; ./a.out
> > func is 0x4004f8, t[0].func is 0x4004f8
> > $ tcc foo.c ; ./a.out
> > func is 0x8048314, t[0].func is (nil)
>
> A bit late for a correct answer but in fact these parenthesis *are* needed.
> There is one set of parenthesis for the array initialization and then one for
> the structure. Gcc with -Wall gives a warning now (since version 4.6).
>
> [SNIP]
>
> Best regards,
>
> Thomas
I think this is sad - it breaks backwards compatibility with C all the way
back to V7.
I'll agree that supplying the braces is better programming style, but
in the case above it really shoudn't be necessary.
Thanks,
Arnold