* gcc brace enclosed initializer problem
@ 2004-12-06 18:48 Jack Marr
2004-12-06 19:14 ` Nathan Sidwell
0 siblings, 1 reply; 2+ messages in thread
From: Jack Marr @ 2004-12-06 18:48 UTC (permalink / raw)
To: gcc-help
We are getting an error due to superfluous braces in an initializer with
g++ 3.3.3. The error is seen here:
% cat brace-enclosed-init.c
int main(void)
{
const char *menu[] =
{
{ "How now" },
{ "Brown cow?" },
};
return 0;
}
% g++ -c brace-enclosed-init.c
brace-enclosed-init.c: In function `int main()':
brace-enclosed-init.c:7: error: brace-enclosed initializer used to
initialize `const char*'
brace-enclosed-init.c:7: error: brace-enclosed initializer used to
initialize `const char*'
We acknowledge that the braces are not needed, but it's not apparent why
this should be an *error* rather than a mere warning as it is when the
same code is compiled with gcc. We've squinted at ISO 14882 section
8.5.1 (dcl.init.aggr), but haven't seen why this should be an *error*.
I understand that gcc/g++ is sometimes more standards compliant than
other compilers, but we're not sure if this is the case here, and
thought this might actually be a g++ bug.
--
Jack Marr (marr@ugs.com)
UGS -- Development Environment Tools
Cypress, CA "Ite Ursi"
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: gcc brace enclosed initializer problem
2004-12-06 18:48 gcc brace enclosed initializer problem Jack Marr
@ 2004-12-06 19:14 ` Nathan Sidwell
0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2004-12-06 19:14 UTC (permalink / raw)
To: Jack Marr; +Cc: gcc-help
Jack Marr wrote:
> We acknowledge that the braces are not needed, but it's not apparent why
> this should be an *error* rather than a mere warning as it is when the
> same code is compiled with gcc. We've squinted at ISO 14882 section
> 8.5.1 (dcl.init.aggr), but haven't seen why this should be an *error*. I
> understand that gcc/g++ is sometimes more standards compliant than other
> compilers, but we're not sure if this is the case here, and thought this
> might actually be a g++ bug.
it is an error. EDG 3.4 rejects the code in strict mode, but gives warnings
in non-strict mode.
8.5.1/2 applies recursively to give '{"how now"}' as an initializer for
a 'char const *' object. 8.5 does not give it as a valid initializer form.
The nearest one gets is /13 which allows an extra set at the top level.
If you feel strongly, submit a bug report.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-12-06 19:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-06 18:48 gcc brace enclosed initializer problem Jack Marr
2004-12-06 19:14 ` Nathan Sidwell
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 read-only IMAP folder(s) and NNTP newsgroup(s).