PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Is a bug with Comeau or I miss something as Comeau says?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Is a bug with Comeau or I miss something as Comeau says?

Réponse
 
LinkBack Outils de la discussion
Vieux 18/10/2007, 03h46   #1
Rasmus Johansen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is a bug with Comeau or I miss something as Comeau says?

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

  Réponse avec citation
Vieux 18/10/2007, 15h17   #2
Barry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 18/10/2007, 16h19   #3
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is a bug with Comeau or I miss something as Comeau says?

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


  Réponse avec citation
Vieux 18/10/2007, 16h44   #4
Barry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is a bug with Comeau or I miss something as Comeau says?

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?
  Réponse avec citation
Vieux 18/10/2007, 17h43   #5
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is a bug with Comeau or I miss something as Comeau says?

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


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14122 seconds with 13 queries