473,668 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
Nov 16 '05 #1
2 1822
>It seems that Unsized Arrays are broken when /Og (Global Optimization) is
enabled.


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
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 16 '05 #2
>'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
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2007
by: Kaptain524 | last post by:
Hello, I am using PHP 5.0.4 with Apache 2, on WinXP Pro. This behavior appears to be fundamental however, and should not be affected by platform. It would seem that there is some kind of bug in the process that creates the reference when it is being assigned to an array element within itself. If it is already referenced, it just assigns the existing reference and avoids the problem.
0
1887
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 241 open ( -6) / 2622 closed (+26) / 2863 total (+20) Bugs : 764 open ( +6) / 4453 closed (+38) / 5217 total (+44) RFE : 150 open ( +2) / 131 closed ( +0) / 281 total ( +2) New / Reopened Patches ______________________
33
3856
by: Peter Seaman | last post by:
I understand that structures are value types and arrays and classes are reference types. But what about arrays as members of structures i.e. as in C struct x { int n; int a; }
10
3065
by: chris | last post by:
I'm not sure if this is a bug being caused by visual studio, or by the vb compiler itself. I have good size solution (33 projects) and am consistently having a problem with one project.. Basically everytime I build, I get the compiler error bc30456...which is basically that some local variable is not declared. However, the variable is declared...and basically if I change its declaration from private to protected the project will...
4
5907
by: Danny Mavromatis | last post by:
I'm trying to set up a structure using unions (fieldoffset) and I'm running into a problem. When I try to setup a union of data array or message type, I get the following error: System.TypeLoadException: Could not load type 'Test.Message' from assembly 'Test, Version=1.0.2228.19435, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 1 that is incorrectly aligned or overlapped by a non-object field. ...
10
4984
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I get an error: ---------------- An unhandled exception of type 'System.NullReferenceException' occured in
12
6462
by: Anil Gupte | last post by:
How can I dimension an array like this: dim info(a as integer, b as string) so I can store somthing like {{"John", 10}{"Dan", 20}{"Jane", 30}} I want to be able to sort this array too, but I think I can swing that if I know how to create this array or whatever else method is needed. -- Anil Gupte www.keeninc.net
16
2532
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over at just comp.lang.c++. If one of these groups is too inappropriate, just take it off from where you send your replies.) Hi.
0
1356
by: Art Cummings | last post by:
Good morning all. I just finished an assignment using structures. In this assignment I used an array of structures. What I would have liked was to use an array of structures with a function. The problem I ran into, was when the i tried to read the data in the structure I got garbage. Normally when I use arrays they retain the information that I enter once the function completes. I'm thinking that it has something to do with using the...
0
8889
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8572
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8652
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.