pure specifier [fun]

Intrebari despre programarea cu VC++ incluzand mediul de dezvoltare, instalare, setari, debugger, compilator, linker si documentatie.
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

pure specifier [fun]

Post by Ovidiu Cucu » 24 Sep 2008, 11:35

Fara a compila codul de mai jos

Code: Select all

static const int a = 0;
#define b 0

struct Foo
{
    virtual void f1() = a;
    virtual void f2() = b;
    virtual void f3() = a + b;
};
la care dintre declaratiile functiilor f1, f2, sau f3 credeti ca rezulta eroarea

Code: Select all

error C2258: illegal pure syntax, must be '= 0'
?



User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: pure specifier [fun]

Post by Marius Bancila » 24 Sep 2008, 14:11

Tare intrebarea. Nu m-am gandit niciodata la asa ceva. As zice ca la ultima (a+b), da nu stiu de ce cred ca tu o sa zici ca de fapt la aia cu b da eroarea.
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

Dragos Cojocari
Membru++
Membru++
Posts: 789
Joined: 11 Jul 2007, 14:11

Re: pure specifier [fun]

Post by Dragos Cojocari » 24 Sep 2008, 15:10

Hehe, oricare ar fi aia cu buba m-as mira sa gasim 2 compilatoare care sa zica la fel.

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: pure specifier [fun]

Post by Ovidiu Cucu » 24 Sep 2008, 15:19

Partea funny e ca linia care da eroarea este:

Code: Select all

virtual void f1() = a;
Celelalte merg.
Merge chiar si o declaratie de forma:

Code: Select all

virtual void f4() = (__int64)(16.0f + a + b + 'A' - 'Q');
:D

// testat pe VS 2005.

User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: pure specifier [fun]

Post by Marius Bancila » 24 Sep 2008, 15:22

Ia uite ce zicea comeau (http://www.comeaucomputing.com/tryitout/):
"ComeauTest.c", line 6: error: badly-formed pure specifier (only "= 0" is allowed)
virtual void f1() = a;
^

"ComeauTest.c", line 8: error: badly-formed pure specifier (only "= 0" is allowed)
virtual void f3() = a + b;
^

"ComeauTest.c", line 1: warning: variable "a" was declared but never referenced
static const int a = 0;
^

2 errors detected in the compilation of "ComeauTest.c".
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: pure specifier [fun]

Post by Ovidiu Cucu » 24 Sep 2008, 15:42

Pai, ne putem pune cu dl. Comeau?... ;)
Ce-i drept, e drept: AFAIK, in standard la pure-specifier spune "=0" si atata.
E interesant insa, daca din anumite motive stiute si nestiute un compiler accepta o expresie constanta cu rezultat (tip intreg) zero, ce-o fi in capu lui daca de exemplu

Code: Select all

virtual void f5() = a * 2;
e kosher, pe cand

Code: Select all

virtual void f1() = a;
nu e. :)

// just chasing own tail... :biggrin:

Dragos Cojocari
Membru++
Membru++
Posts: 789
Joined: 11 Jul 2007, 14:11

Re: pure specifier [fun]

Post by Dragos Cojocari » 24 Sep 2008, 17:38

Motivele stiute si nestiute "e" de fapt 1 singur: compilatoarele nu prea sunt 100% conforme cu standarul. Unele "e" 95% altele , nu dam nume stim noi cine, sunt probabil doar 80%.

Post Reply