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 > variable declaration
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
variable declaration

Réponse
 
LinkBack Outils de la discussion
Vieux 21/02/2008, 18h27   #1
Rahul
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut variable declaration

Hi Everyone,

I had the following declaration and i expected the compiler to give
an error, but it didn't, how does it interpret the declaration?

const * int ptr;

Thanks in advance!!!
  Réponse avec citation
Vieux 21/02/2008, 19h21   #2
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable declaration

Rahul wrote:
> I had the following declaration and i expected the compiler to give
> an error, but it didn't, how does it interpret the declaration?
>
> const * int ptr;


You should probably ask the compiler or its developers. The '*'
symbol cannot be followed by 'int'. Could be a bug in the compiler.

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 21/02/2008, 21h44   #3
Juha Nieminen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable declaration

Victor Bazarov wrote:
> The '*' symbol cannot be followed by 'int'.


result = a * int (b);


  Réponse avec citation
Vieux 21/02/2008, 21h58   #4
Jeff Schwab
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable declaration

Juha Nieminen wrote:
> Victor Bazarov wrote:
>> The '*' symbol cannot be followed by 'int'.

>
> result = a * int (b);


What compiler does that? GCC 4.2 rejects both of these:

int main() { const * int ptr; }
int main() { void* ptr = 0; const * int ptr; }

Both cases cause the same diagnostic:

g++ -ansi -pedantic -Wall main.cc -o main
main.cc: In function 'int main()':
main.cc:1: error: expected unqualified-id before 'int'
main.cc:1: error: expected initializer before 'int'
  Réponse avec citation
Vieux 21/02/2008, 22h02   #5
Victor Bazarov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable declaration

Juha Nieminen wrote:
> Victor Bazarov wrote:
>> The '*' symbol cannot be followed by 'int'.

>
> result = a * int (b);
>
>


I meant in a declaration. See subj.

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 21/02/2008, 22h22   #6
Jeff Schwab
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable declaration

Jeff Schwab wrote:
> Juha Nieminen wrote:
>> Victor Bazarov wrote:
>>> The '*' symbol cannot be followed by 'int'.

>>
>> result = a * int (b);

>
> What compiler does that? GCC 4.2 rejects both of these:
>
> int main() { const * int ptr; }
> int main() { void* ptr = 0; const * int ptr; }
>
> Both cases cause the same diagnostic:
>
> g++ -ansi -pedantic -Wall main.cc -o main
> main.cc: In function 'int main()':
> main.cc:1: error: expected unqualified-id before 'int'
> main.cc:1: error: expected initializer before 'int'


I should have mentioned that trying to assign "a * int b" produces a
similar diagnostic: "expected primary-expression before 'int'".
  Réponse avec citation
Vieux 24/02/2008, 09h16   #7
terminator
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable declaration

On Feb 22, 1:22am, Jeff Schwab <j...@schwabcenter.com> wrote:
> Jeff Schwab wrote:
> > Juha Nieminen wrote:
> >> Victor Bazarov wrote:
> >>> The '*' symbol cannot be followed by 'int'.

>
> >> result = a * int (b);

>
> > What compiler does that? GCC 4.2 rejects both of these:

>
> > int main() { const * int ptr; }
> > int main() { void* ptr = 0; const * int ptr; }

>
> > Both cases cause the same diagnostic:

>
> > g++ -ansi -pedantic -Wall main.cc -o main
> > main.cc: In function 'int main()':
> > main.cc:1: error: expected unqualified-id before 'int'
> > main.cc:1: error: expected initializer before 'int'

>
> I should have mentioned that trying to assign "a * int b" produces a
> similar diagnostic: "expected primary-expression before 'int'".


you`ve missed the braces around 'b'.

regards,
FM.
  Réponse avec citation
Vieux 24/02/2008, 16h11   #8
Jeff Schwab
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: variable declaration

terminator wrote:
> On Feb 22, 1:22 am, Jeff Schwab <j...@schwabcenter.com> wrote:
>> Jeff Schwab wrote:
>>> Juha Nieminen wrote:
>>>> Victor Bazarov wrote:
>>>>> The '*' symbol cannot be followed by 'int'.
>>>> result = a * int (b);
>>> What compiler does that? GCC 4.2 rejects both of these:
>>> int main() { const * int ptr; }
>>> int main() { void* ptr = 0; const * int ptr; }
>>> Both cases cause the same diagnostic:
>>> g++ -ansi -pedantic -Wall main.cc -o main
>>> main.cc: In function 'int main()':
>>> main.cc:1: error: expected unqualified-id before 'int'
>>> main.cc:1: error: expected initializer before 'int'

>> I should have mentioned that trying to assign "a * int b" produces a
>> similar diagnostic: "expected primary-expression before 'int'".

>
> you`ve missed the braces around 'b'.


Yes, I know. That's the point.

Juha snipped the part that would have made that clear, and I did not put
it back. Please see the original post in this thread.
  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 07h19.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12025 seconds with 16 queries