473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Is a bug with Comeau or I miss something as Comeau says?

<code>
struct A {};

int main()
{
const A ca;
}
</code>

<output>
"ComeauTest.c", line 5: error: const variable "ca" requires an
initializer -- class
"A" has no explicitly declared default constructor
const A ca;
</output>

I don't find any thing in standard to support Comeau.
If it's a bug with Comeau, then it's quite silly.
If I was wrong, then I was doing this wrong all the time.
Oct 18 '07 #1
4 1249
Barry wrote:
<code>
struct A {};

int main()
{
const A ca;
}
</code>

<output>
"ComeauTest.c", line 5: error: const variable "ca" requires an
initializer -- class
"A" has no explicitly declared default constructor
const A ca;
</output>

I don't find any thing in standard to support Comeau.
Look in [dcl.init]/9.
If it's a bug with Comeau, then it's quite silly.
If I was wrong, then I was doing this wrong all the time.
[dcl.init]/9:

"If no initializer is specified for an object, and the object is
of (possibly cv-qualified) non-POD class type (or array thereof),
the object shall be default-initialized; if the object is of
const-qualified type, the underlying class type shall have a user-
declared default constructor. Otherwise, if no initializer is
specified for a non-static object, the object and its subobjects,
if any, have an indeterminate initial value92); if the object or
any of its subobjects are of const-qualified type, the program is
ill-formed."

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 18 '07 #2
Victor Bazarov wrote:

Thanks V,

what if I use C structs in cxx files?

After the inclusion of header file
the code looks like this:

extern "C"
{
struct A {};
}

int main()
{
const A ca;
}

But we can't change the original definition of struct A.
So we just can't declare /ca/ of /const A/ ?

What's the point that the language constrains on this?
Oct 18 '07 #3
Barry wrote:
Victor Bazarov wrote:

Thanks V,

what if I use C structs in cxx files?
There is no such thing. If you mean "what if I use POD structs
in my C++ program", then the question is legitimate. But you're
not gonna like the answer anyway, sorry. What do you mean "what
if you use C structs"?
After the inclusion of header file
the code looks like this:

extern "C"
{
struct A {};
}

int main()
{
const A ca;
}

But we can't change the original definition of struct A.
So we just can't declare /ca/ of /const A/ ?

What's the point that the language constrains on this?
No, you just need to provide a proper initialiser:

int main()
{
const A ca = {};
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 18 '07 #4
"Barry" wrote:
What's the point that the language constrains on this?
The point is to avoid having an object in an indeterminate state which can't
get out of it. What would the point of your code be? As the snippet from the
standard clearly states the object will be in an indeterminate state because
it's a POD-class, and since you declared it const you can't change it, so
you'd simply have an unusable object.

Oct 18 '07 #5

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

Similar topics

4
by: Icosahedron | last post by:
I'm sure it's been done. I'm sure that I'm an idiot for even asking the question, but has anyone been successful in getting Comeau 4.3.0.1 to compile STLPort, or even use STLPort in a program...
7
by: Bob Hairgrove | last post by:
Hi, The Digital Mars compiler is not listed on the Dinkumware library's compatibility list on their web site. I would like to use the Dinkumware STL (source code license) together with the...
9
by: Theodore Huxibolde | last post by:
The Comeau C++ web site does not appear to have been updated in nearly a year, but I do notice that Mr. Comeau does post here quite freqently. Is this compiler still being actively developed and...
3
by: Joe | last post by:
Does anybody know if Comeau intends to support newer versions of GCC or not? Thanks
12
by: nicdude | last post by:
There is a Comeau C++ compiler special offer at http://www.comeaucomputing.com Is it really as compliant as it seems to imply? In terms of Standard C++, what is it missing? Can it handle...
4
by: Axter | last post by:
Sorry for OT question, but does any one have a working *.bat file to get Comeau to work with VC++ 7.1, VC++ 8.0, or GNU 3.x compilers. I've tried everything I can think off, to get it to work,...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
4
by: Alan Woodland | last post by:
Hi, I was trying to come up with obscure C++ questions in the style of GoTW and ran across this unexpected difference between G++ and comeau. Can anyone point me in the direction of the correct...
1
by: Stefan Naewe | last post by:
Given the following: // ++ CODE struct S { const int ci; }; int main()
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.