Cygwin gcc "initializer element is not constant" problem
Igor Pechtchanski
pechtcha@cs.nyu.edu
Thu Jan 2 20:08:00 GMT 2003
On Thu, 2 Jan 2003, Jason Tishler wrote:
> The attached code snippet, j2.c, demonstrates a Cygwin specific
> compilation problem that affects many Python shared extension modules:
>
> $ gcc -c j2.c
> j2.c:17: initializer element is not constant
> j2.c:17: (near initialization for `f.get')
>
> It appears that Cygwin gcc considers function pointers marked
> "__declspec(dllimport)" unacceptable to use as initializer constants.
>
> My standard workaround is to submit a patch that is the equivalent of
> compiling this snippet with -DWORKAROUND:
>
> $ gcc -DWORKAROUND -c j2.c
>
> Unfortunately, this style of patch is no longer acceptable:
>
> http://mail.python.org/pipermail/python-dev/2002-December/031534.html
>
> Can anyone suggest a better (hopefully less intrusive) workaround?
>
> Thanks,
> Jason
Jason,
I believe the complaint was not about the intrusiveness (i.e. patch size)
of the workaround, but about the readability of the resulting code.
How about doing exactly what the message suggests (see attached)?
Igor
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
Oh, boy, virtual memory! Now I'm gonna make myself a really *big* RAMdisk!
-- /usr/games/fortune
-------------- next part --------------
#ifndef WORKAROUND
# define INITIAL(v) (v)
# define ASSIGN(f,v)
#else
# define INITIAL(v) (0)
# define ASSIGN(f,v) do{ f = v; }while(0)
#endif
typedef void (*function)();
struct foo
{
function get;
};
__declspec(dllimport) void f1();
struct foo f =
{
INITIAL(f1)
};
void
init()
{
ASSIGN(f.get, f1);
}
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list