BUG: unsized arrays in structures are broken when /Og is used

A

Andrew Burlak

Hi,

Although Unsized Arrays inside structures is a non-standard feature, I like
to use it :)

It seems that Unsized Arrays are broken when /Og (Global Optimization) is
enabled.
The problem occurs whenever the unsized array is declared as 'const'.

Here is an example:
//----------------------
#include "stdio.h"

#pragma warning (disable: 4200) // nonstandard extension used : zero-sized
array in struct/union

struct Foo
{
char str[];
};

struct Bar
{
char const str[];
};

Foo const foo = {"foo"};
Bar const bar = {"bar"};

void main()
{
printf (foo.str);
printf (bar.str);
}
//----------------------

Here is the output:
/Og disabled: foobar
/Og enabled: foo

Strange, isn't it?

BTW, in VC6, it was not possible to declare the unsized array inside a
structure as 'const', because VC6 considered such structures
non-aggregates - it was impossible to initialize such structures.

Best regards,
Andrew Burlak
 
D

David Lowndes

It seems that Unsized Arrays are broken when /Og (Global Optimization) is

Andrew,

Using VC7.1 I get your failure result when I don't use /Og. A normal
debug build is OK, while a normal Release build reproduces the
problem.

If someone from MS doesn't reply I'll try to forward your report on to
them.

Dave
 
D

David Lowndes

'Normal' Release build (default configuration) uses /O2 (Maximize Speed),
which implies /Og.

My mistake, I was getting confused with "Whole Program Optimization"
/GL.

I've tried to pass on the report to MS.

Dave
 
Top