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
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