This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC 4.5: "nonconstant array index in initializer" error
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Denis Onischenko <denis dot onischenko at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 23 Apr 2009 15:31:57 +0000 (UTC)
- Subject: Re: GCC 4.5: "nonconstant array index in initializer" error
- References: <c80516030904230031j2f9916a7t7ed05ad53cffd426@mail.gmail.com>
On Thu, 23 Apr 2009, Denis Onischenko wrote:
> The following errors appears when I tried to compile linux kernel
> 2.6.30-rc2 with GCC 4.5:
>
>
> linux-2.6/drivers/gpu/drm/drm_drv.c:59: error: nonconstant array index
> in initializer
> linux-2.6/drivers/gpu/drm/drm_drv.c:59: error: (near initialization
> for 'drm_ioctls')
> ...
>
> compiled code looks like this:
>
> static struct drm_ioctl_desc drm_ioctls[] = {
> DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, 0),
> DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
> ...
>
> where DRM_IOCTL_DEF defined as
>
> #define DRM_IOCTL_DEF(ioctl, _func, _flags) \
> [DRM_IOCTL_NR(ioctl)] = {.cmd = ioctl, .func = _func, .flags = _flags}
And how is DRM_IOCTL_NR defined? To be used here it should be defined to
expand to an integer constant expression.
> If it is not a bug, is there a way to disable this conformance rules
> checking with GCC 4.5 ?
There is no general way. In particular cases the errors can be made into
pedwarns or pedwarns-if-pedantic if there seems to be a good reason for a
coding style not letting proper integer constant expressions be used in a
particular case.
--
Joseph S. Myers
joseph@codesourcery.com