/ Forside / Teknologi / Udvikling / C/C++ / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
C/C++
#NavnPoint
BertelBra.. 2425
pmbruun 695
Master_of.. 501
jdjespers.. 500
kyllekylle 500
Bech_bb 500
scootergr.. 300
gibson 300
molokyle 287
10  strarup 270
Scope for midlertidige variable i C++
Fra : Bertel Lund Hansen


Dato : 06-02-02 17:04

Hej alle

Eksempel:

1   for (int nr=0; nr<100; ++nr) {
2      cout << nr << endl;
3   }
4   cout << nr;

VC++ udskriver fint en værdi; Borlands C++ 5.5 siger i linje 4 at
nr er en ukendt variabel.

Under ingen omstændigheder vil jeg bryde mig om at genbruge en
variabel som erklæres inde i en løkke, men hvad er korrekt
C++-opførsel?

--
Bertel
http://lundhansen.dk/bertel/   FIDUSO: http://fiduso.dk/

 
 
Mads Kristiansen (06-02-2002)
Kommentar
Fra : Mads Kristiansen


Dato : 06-02-02 17:23

> 1 for (int nr=0; nr<100; ++nr) {
> 2 cout << nr << endl;
> 3 }
> 4 cout << nr;
> Under ingen omstændigheder vil jeg bryde mig om at genbruge en
> variabel som erklæres inde i en løkke, men hvad er korrekt
> C++-opførsel?

Variabler defineret i en for-loop er kun synlige inden i loopet. Følgende
burde da være muligt:
1: for (int nr=0; nr<100; ++nr);
2: for (int nr=0; nr<100; ++nr);
Integer-definitonen på anden linie definerer en integer, som ikke er
relateret til den første.

Nogle compilere implementerer samme opførsel som VC++, hvilket altså ikke er
standard C++.

Mvh Mads





Igor V. Rafienko (06-02-2002)
Kommentar
Fra : Igor V. Rafienko


Dato : 06-02-02 17:32

[ Bertel Lund Hansen ]

[ snip ]

> Under ingen omstændigheder vil jeg bryde mig om at genbruge en
> variabel som erklæres inde i en løkke, men hvad er korrekt
> C++-opførsel?


VC++ tar feil, Borland har rett. Skopet til variable deklarert i
"init" delen av en for-løkke er for-løkken.

[ quote 6.5.3, p 3 ]

If the for-init-statement is a declaration, the cope of the name(s)
declared extends to the end of the for-statement. [Example:

int i = 42;
int a[10];

for ( int i = 0; i < 10; i++ )
   a[i] = i;

int j = i;       // j = 42

--end example]

[ /quote ]





ivr
--
The C language combines all the power of assembly language with all
the ease-of-use of assembly language.
      -- P. van der Linden "Expert C Programming"

Daniel Nielsen (06-02-2002)
Kommentar
Fra : Daniel Nielsen


Dato : 06-02-02 18:01

On 06/02/02 17.04, Bertel Lund Hansen wrote:
> Hej alle
>
> Eksempel:
>
> 1   for (int nr=0; nr<100; ++nr) {
> 2      cout << nr << endl;
> 3   }
> 4   cout << nr;
>
> VC++ udskriver fint en værdi; Borlands C++ 5.5 siger i linje 4 at
> nr er en ukendt variabel.
>
> Under ingen omstændigheder vil jeg bryde mig om at genbruge en
> variabel som erklæres inde i en løkke, men hvad er korrekt
> C++-opførsel?
>
> --
> Bertel
> http://lundhansen.dk/bertel/   FIDUSO: http://fiduso.dk/

Jeg er ikke den store c++ haj, men... med tanke paa det oversaetter
kursus jeg lige har haft, er det temmeligt grimt at vc++ lader dig
goere det!

/Daniel

--
Daniel | "Face it. You *need* some cola. It runs through your
Nielsen | blood and *sings* to you. Obtain. Open. Drink. Frolic."
| - Can of Cola (userfriendly 30.11.99)
Phone: +45 61 30 33 09


Bertel Lund Hansen (06-02-2002)
Kommentar
Fra : Bertel Lund Hansen


Dato : 06-02-02 18:30

Daniel Nielsen skrev:

>Jeg er ikke den store c++ haj, men... med tanke paa det oversaetter
>kursus jeg lige har haft, er det temmeligt grimt at vc++ lader dig
>goere det!

Tak for alle svarene.

Borland stiller en gratis kompiler til rådighed der overholder
standarden. M$ sælger en der ikke gør. Der er intet nyt under
solen.

--
Bertel
http://lundhansen.dk/bertel/   FIDUSO: http://fiduso.dk/

Mads Kristiansen (06-02-2002)
Kommentar
Fra : Mads Kristiansen


Dato : 06-02-02 21:05

> Borland stiller en gratis kompiler til rådighed der overholder
> standarden. M$ sælger en der ikke gør. Der er intet nyt under
> solen.

Til det vil jeg lige tilføje, at man med VC6 kan kan bruge kommandolinie
parameter /Za. Den deaktiverer "Microsoft language-extensions" og skulle
gerne sørge for at variabler deklareret i for-løkker har det rigtige scope
ifølge ANSI-standarden.. Desværre er der vist en del "bivirkninger", så om
det kan betale sig at slå den fra i det hele taget, skal jeg ikke kunne
sige.. :|

gcc version 2.7.0 implemeterede den dengang nye ANSI-regel om scope for
varabler deklareret i loops, men man kan dog bruge -fno-for-scope, hvilket
resulterer i samme opførsel som standard VC6 uden sære switches.

Mvh Mads





Mogens Hansen (06-02-2002)
Kommentar
Fra : Mogens Hansen


Dato : 06-02-02 22:14


"Mads Kristiansen" <mjkristiansen@hotmail.com> wrote in message
>
> Til det vil jeg lige tilføje, at man med VC6 kan kan bruge kommandolinie
> parameter /Za. Den deaktiverer "Microsoft language-extensions" og skulle
> gerne sørge for at variabler deklareret i for-løkker har det rigtige scope
> ifølge ANSI-standarden.. Desværre er der vist en del "bivirkninger", så om
> det kan betale sig at slå den fra i det hele taget, skal jeg ikke kunne
> sige.. :|
>

Følgende program

#include <iostream>

using namespace std;

int main(void)
{
for(int i = 0; 10 != i; ++i)
cout << i;
for(int i = 0; 10 != i; ++i)
cout << i;

return 0;
}

oversætter det uden problemer Med Microsoft Visual C++ .NET med /Za.
Med Microsoft Visual C++ V6.0 SP 4 (?) med /Za, giver et resultat som tyder
på at det er problematisk i praksis.
Det indikerer samtidigt endnu en gang at Microsoft Visual C++ .NET er en
væsentlig, og tiltrængt, forbedring i forhold til Microsoft Visual C++ V6.0,
i relation til implementering af C++ sproget.

--------------------Configuration: fnyt - Win32 Release--------------------
Compiling...
fnyt.cpp
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(81) : error
C2146: syntax error : missing ';' before identifier 'iterator_category'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(81) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(81) : error
C2501: 'iterator_category' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(82) : error
C2146: syntax error : missing ';' before identifier 'value_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(82) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(82) : error
C2501: 'value_type' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(83) : error
C2146: syntax error : missing ';' before identifier 'distance_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(83) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(83) : error
C2501: 'distance_type' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(84) :
see reference to class template instantiation 'std::iterator_traits<_It>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(226) : error
C2974: 'iterator' : invalid template argument for '_D', type expected
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(71) :
see declaration of 'iterator'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(279) :
see reference to class template instantiation
'std::istreambuf_iterator<_E,_Tr>' being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(231) : error
C2146: syntax error : missing ';' before identifier 'int_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(279) :
see reference to class template instantiation
'std::istreambuf_iterator<_E,_Tr>' being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(231) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(279) :
see reference to class template instantiation
'std::istreambuf_iterator<_E,_Tr>' being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(231) : error
C2501: 'int_type' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(279) :
see reference to class template instantiation
'std::istreambuf_iterator<_E,_Tr>' being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(25) : error
C2146: syntax error : missing ';' before identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(25) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(25) : error
C2501: 'size_type' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(26) : error
C2146: syntax error : missing ';' before identifier 'difference_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(26) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(26) : error
C2501: 'difference_type' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(27) : error
C2146: syntax error : missing ';' before identifier 'pointer'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(27) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(27) : error
C2501: 'pointer' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(28) : error
C2146: syntax error : missing ';' before identifier 'const_pointer'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(28) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(28) : error
C2501: 'const_pointer' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(29) : error
C2146: syntax error : missing ';' before identifier 'reference'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(29) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(29) : error
C2501: 'reference' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(30) : error
C2146: syntax error : missing ';' before identifier 'const_reference'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(30) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(30) : error
C2501: 'const_reference' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(31) : error
C2146: syntax error : missing ';' before identifier 'value_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(31) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(31) : error
C2501: 'value_type' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(32) : error
C2146: syntax error : missing ';' before identifier 'iterator'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(32) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(32) : error
C2208: 'struct std::iterator' : no members defined using this type
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(33) : error
C2146: syntax error : missing ';' before identifier 'const_iterator'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(33) : error
C2838: illegal qualified name in member declaration
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(33) : error
C2501: 'const_iterator' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(34) : error
C2065: 'const_iterator' : undeclared identifier
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(34) : error
C2065: 'value_type' : undeclared identifier
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(35) : error
C2065: 'const_reference' : undeclared identifier
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(35) : error
C2065: 'const_pointer' : undeclared identifier
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(35) : error
C2065: 'difference_type' : undeclared identifier
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(37) : error
C2955: 'iterator' : use of class template requires template argument list
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\utility(71) :
see declaration of 'iterator'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(38) : error
C2065: 'reference' : undeclared identifier
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(38) : error
C2065: 'pointer' : undeclared identifier
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(45) : error
C2629: unexpected 'class std::basic_string<_E,_Tr,_A> ('
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(45) : error
C2334: unexpected token(s) preceding ':'; skipping apparent function body
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(48) : error
C2629: unexpected 'class std::basic_string<_E,_Tr,_A> ('
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(48) : error
C2334: unexpected token(s) preceding ':'; skipping apparent function body
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(53) : error
C2629: unexpected 'class std::basic_string<_E,_Tr,_A> ('
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(53) : error
C2334: unexpected token(s) preceding ':'; skipping apparent function body
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(55) : error
C2146: syntax error : missing ';' before identifier '_It'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(55) : error
C2501: '_It' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(56) : error
C2629: unexpected 'class std::basic_string<_E,_Tr,_A> ('
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(56) : error
C2334: unexpected token(s) preceding ':'; skipping apparent function body
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(63) : error
C2146: syntax error : missing ';' before identifier 'npos'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(63) : error
C2501: 'npos' : missing storage-class or type specifiers
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(78) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(79) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::append(const class
std::basic_string<_E,_Tr,_A> &)' : member function already defined or d
eclared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(76) :
see declaration of 'append'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(90) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(99) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::append(const _E *)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(90) :
see declaration of 'append'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(100) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(108) : error
C2061: syntax error : identifier '_It'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(109) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::append(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(100) :
see declaration of 'append'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(112) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(113) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::assign(const class
std::basic_string<_E,_Tr,_A> &)' : member function already defined or
declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(110) :
see declaration of 'assign'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(132) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(138) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::assign(const _E *)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(132) :
see declaration of 'assign'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(139) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(146) : error
C2061: syntax error : identifier '_It'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(147) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::assign(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(139) :
see declaration of 'assign'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(148) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(150) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(152) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::insert(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(148) :
see declaration of 'insert'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(164) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(165) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::insert(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(148) :
see declaration of 'insert'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(175) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(176) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::insert(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(148) :
see declaration of 'insert'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(177) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(178) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::insert(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(148) :
see declaration of 'insert'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(192) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(195) : error
C2061: syntax error : identifier '_It'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(196) : error
C2535: 'void __thiscall std::basic_string<_E,_Tr,_A>::insert(struct
std::iterator)' : member function already defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(192) :
see declaration of 'insert'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(197) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(218) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(220) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(222) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::replace(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(218) :
see declaration of 'replace'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(241) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(243) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::replace(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(218) :
see declaration of 'replace'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(260) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(261) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::replace(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(218) :
see declaration of 'replace'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(262) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(264) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::replace(void)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(218) :
see declaration of 'replace'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(286) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(290) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::replace(struct std::iterator,struct
std::iterator,const _E *)' : member function already
defined or declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(285) :
see declaration of 'replace'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(292) : error
C2061: syntax error : identifier 'size_type'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(296) : error
C2061: syntax error : identifier '_It'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(297) : error
C2535: 'class std::basic_string<_E,_Tr,_A> &__thiscall
std::basic_string<_E,_Tr,_A>::replace(struct std::iterator,struct
std::iterator)' : member function already defined or
declared
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(292) :
see declaration of 'replace'
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(297) : fatal
error C1003: error count exceeds 100; stopping compilation
G:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(597) :
see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>'
being compiled
Error executing xicl6.exe.

fnyt.exe - 102 error(s), 0 warning(s)


Venlig hilsen

Mogens Hansen



Anders Borum (07-02-2002)
Kommentar
Fra : Anders Borum


Dato : 07-02-02 01:41

"Bertel Lund Hansen" <nospam@lundhansen.dk> skrev i en meddelelse
news:8tp26u49mgb9as2440cadeter8eo65lr9r@sunsite.auc.dk...
> Daniel Nielsen skrev:
[klip]
> Borland stiller en gratis kompiler til rådighed der overholder
> standarden. M$ sælger en der ikke gør. Der er intet nyt under
> solen.

Da de første udgaver af Visual C++ kom på banen for mange år siden var der
bred enighed om at variablen erklæret i en for-løkke skulle være synlig også
efter løkken. Sådan gjorde Borland det fx. også.
Så kom _standarden_ der besluttede at variablen ikke længere måtte være
synlig uden for løkken. På dette tidspunkt var der skrevet mange linier kode
der afhang af den gamle virkemåde.

Microsoft har åbenbart prioriteret kodekompatibilitet over opfyldelse af
standarden og det er da ikke et entydigt dårligt valg, selvom man kan være
uenig.

Hilsen Anders



Igor V. Rafienko (07-02-2002)
Kommentar
Fra : Igor V. Rafienko


Dato : 07-02-02 03:10

[ Anders Borum ]

[ snip ]

> Microsoft har åbenbart prioriteret kodekompatibilitet over
> opfyldelse af standarden og det er da ikke et entydigt dårligt valg,
> selvom man kan være uenig.


Det er et _hjerneskadet_ valg, da allerede på midten av 90-tallet var
det klart at skopreglene for for-løkker ikke var entydige (jeg likte
forøvrig utrolig dårlig forklaringen til Stroustrup i D&EC++. Rett meg
om jeg tar feil, men var det ikke slik at skopet til variable
introdusert i if-setninger var nettopp if-setninger?). Det man _burde_
ha gjort var å lage en opsjon til kompilatoren som tolket skopet den
ene eller den andre veien og såsnart standarden kom ut bruke
standarden som "default" modus.

Men neida, det var altfor vanskelig. Av og til lurer jeg på _hvordan_
en såpass stor leverandør av programmvare kan være så _usedvanlig_
dum.





ivr
PS: Anders, beklager hvis du får denne i mail også. 'f' og 'r' er
veldig nærme når klokken er 03:00.
--
Copyright, ËÁË ÉÚ×ÅÓÔÎÏ, ÏÚÎÁÞÁÅÔ "ÓËÏÐÉÒÏ×ÁÎÏ ÐÒÁ×ÉÌØÎÏ".
      -- BOFH jokes, Russian translation.

Mogens Hansen (07-02-2002)
Kommentar
Fra : Mogens Hansen


Dato : 07-02-02 07:11


"Anders Borum" <overflade@fedt.dk> wrote in message
news:J4k88.999$5L3.106099@news010.worldonline.dk...

> Så kom _standarden_ der besluttede at variablen ikke længere måtte være
> synlig uden for løkken. På dette tidspunkt var der skrevet mange linier
kode
> der afhang af den gamle virkemåde.
>

Beslutningen om scope i for løkker blev taget adskillige år før den nu mere
end 3 år gamle standard blev formelt vedtaget.
Ændringen i scope bliver i øvrigt nemt fanget på compile-time, hvis man har
baseret sig på det gamle scope regler, så den er relativt ufarlig.
Det er nemt at ændre koden, hvis man har brug for det:

int i = 0;
for(; 10 != i; ++i) {
// ...
}
++i;

Naturligvis bør compilere have optioner til at være bagud compatible, men
default bør være overholdelse af standarden. Default for Microsoft Visual
C++ .NET er den gamle scope regel, altså ikke overholdelse af standarden,
men der er en switch til at ændre det.


Venlig hilsen

Mogens Hansen



Ivan Johansen (07-02-2002)
Kommentar
Fra : Ivan Johansen


Dato : 07-02-02 12:09

Mogens Hansen wrote:

> Naturligvis bør compilere have optioner til at være bagud compatible, men
> default bør være overholdelse af standarden. Default for Microsoft Visual
> C++ .NET er den gamle scope regel, altså ikke overholdelse af standarden,
> men der er en switch til at ændre det.


Det er en god måde at lære folk ikke at overholde standarden.

Ivan Johansen



Mads Kristiansen (07-02-2002)
Kommentar
Fra : Mads Kristiansen


Dato : 07-02-02 13:15

> Det er en god måde at lære folk ikke at overholde standarden.

Til dem, der måtte være interesserede, fandt jeg dette link omhandlende
VC6-afvigelser fra standarden:

"INFO: C++ Standard Noncompliance Issues with Visual C++ 6.0 (Q243451)"
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q243451

MS giver også en alternativ løsning på for-løkke problematikken udover
"/Za"-switchen i Q167748, men om man så kan lide den, er jo en anden sag ..
;)

/ Mads




Jonas Meyer Rasmusse~ (07-02-2002)
Kommentar
Fra : Jonas Meyer Rasmusse~


Dato : 07-02-02 20:19


"Ivan Johansen" <NG@Padowan.dk> wrote in message
news:3C626044.3050705@Padowan.dk...
> Mogens Hansen wrote:
>
> > Naturligvis bør compilere have optioner til at være bagud compatible,
men
> > default bør være overholdelse af standarden. Default for Microsoft
Visual
> > C++ .NET er den gamle scope regel, altså ikke overholdelse af
standarden,
> > men der er en switch til at ændre det.
>
>
> Det er en god måde at lære folk ikke at overholde standarden.

Nej ikke her.
Det er korrekt når mogens siger du kan bruge deres underlige scope per
default, men
som noget nyt, så skriver den en pæn warning til dig om at du benytter dig
af en MS udvidelse som
ikke er standard.
Den er meget tydelig, og hvis man ikke læser sine warnings, så er man selv
ude om det :)

mvh Jonas



Mogens Hansen (07-02-2002)
Kommentar
Fra : Mogens Hansen


Dato : 07-02-02 21:37


"Jonas Meyer Rasmussen" <meyer_remove_@diku.dk> wrote in message
news:a3ujud$n4k$1@eising.k-net.dk...
>
>
> Nej ikke her.
> Det er korrekt når mogens siger du kan bruge deres underlige scope per
> default, men
> som noget nyt, så skriver den en pæn warning til dig om at du benytter dig
> af en MS udvidelse som
> ikke er standard.

Hvilken warning får du ?

Når jeg oversætter

#include <iostream>

int main(void)
{
using std::cout;

for(unsigned i = 0; 10 != i; ++i)
cout << i << '\n';

cout << i;
}

med Microsoft Visual C++ .NET (ikke beta eller release candidate), med
default projekt opsætninger får jeg absolut ingen warnings.
Compilerens melding er:

------ Build started: Project: fnyt12, Configuration: Debug Win32 ------

Compiling...
fnyt12.cpp
Linking...

Build log was saved at "file://g:\cpp\fnyt12\Debug\BuildLog.htm"
fnyt12 - 0 error(s), 0 warning(s)


---------------------- Done ----------------------

Build: 1 succeeded, 0 failed, 0 skipped


Hvis jeg derimod skriver (bemærk den æld-gamle form for include)

#include <iostream.h>

int main(void)
{
for(unsigned i = 0; 10 != i; ++i)
cout << i << '\n';

cout << i;
}

får jeg en rimelig warning.
Bemærk at advarslen stammer fra biblioteket og ikke intern fra compileren.
En kommentar i headerfilen siger at den gamle include form ikke vil være
understøttet fra næste store release (VC8), og det er vel en rimelig måde at
holde bagud kompatibilitet i en periode kombineret med passende advarsler.
Man kan naturligvis diskuttere hvornår denne process skulle være påbegyndt.

------ Build started: Project: fnyt12, Configuration: Debug Win32 ------

Compiling...
fnyt12.cpp
g:\Program Files\Microsoft Visual Studio .NET\Vc7\include\useoldio.h(29) :
warning C4995: '_OLD_IOSTREAMS_ARE_DEPRECATED': name was marked as #pragma
deprecated
Linking...

Build log was saved at "file://g:\cpp\fnyt12\Debug\BuildLog.htm"
fnyt12 - 0 error(s), 1 warning(s)


---------------------- Done ----------------------

Build: 1 succeeded, 0 failed, 0 skipped


Det forekommer mig således ikke at være en konsekvent regel, at man får
advarsler i Microsoft Visual C++ .NET, når man bruger gamle konstruktioner,
som er understøttet af hensyn til bagud kompatibilitet.

Venlig hilsen

Mogens Hansen



Jonas Meyer Rasmusse~ (07-02-2002)
Kommentar
Fra : Jonas Meyer Rasmusse~


Dato : 07-02-02 22:02

ak, du har ret, jeg min melder heller ikke fejl ved det program du viser.

Jeg testede med dette

int main(){
int i;
for( int i =0; i < 1; ++i);
std::cout << i;
}

hvilket giver den klare fejl-besked jeg talte om:

d:\code\warning\warning.cpp(10) : warning C4288: nonstandard extension used
: 'i' : loop control variable declared in the for-loop is used outside the
for-loop scope; it conflicts with the declaration in the outer scope
d:\code\warning\warning.cpp(9) : definition of 'i' used
d:\code\warning\warning.cpp(8) : definition of 'i' ignored

Desværre har du ret og de skuffer endnu engang.
mvh Jonas



Jesper (07-02-2002)
Kommentar
Fra : Jesper


Dato : 07-02-02 22:36

Mogens Hansen wrote:

> Ændringen i scope bliver i øvrigt nemt fanget på compile-time, hvis man
> har baseret sig på det gamle scope regler, så den er relativt ufarlig.

Oftest måske, men ikke altid. Denne her burde slippe igennem begge, med
forskellig betydning.

----
int i = 0;
{
for (int i = 0; i < 10; i++) {
....
}
cout << i;
}
----

--
Jesper

Mogens Hansen (08-02-2002)
Kommentar
Fra : Mogens Hansen


Dato : 08-02-02 07:05


"Jesper" <news@skydiver.dkk> wrote in message
news:a3us0j$sdg$1@sneaky.wowweb.dk...
> Mogens Hansen wrote:
>
> > Ændringen i scope bliver i øvrigt nemt fanget på compile-time, hvis man
> > har baseret sig på det gamle scope regler, så den er relativt ufarlig.
>
> Oftest måske, men ikke altid. Denne her burde slippe igennem begge, med
> forskellig betydning.
>

Det har du ret i, men compileren vil kunne give en warning for tvetydigheden
i henhold til den æld-gamle scope regel og den rigtige regel.

> ----
> int i = 0;
> {
> for (int i = 0; i < 10; i++) {
> ....
> }
> cout << i;
> }
> ----

Microsoft Visual C++ .NET giver en warning, som Jonas Meyer Rasmussen
påpegede, for ovenstående kode uanset hvilken scope regel der anvendes.
Men påstand er fortsat at ændringen i scope nemt kan fanges på compiletime,
så i relation til bagud compatibilitet er det relativt ufarligt.

<æld-gamle scope regel>
------ Build started: Project: fnyt12, Configuration: Debug Win32 ------

Compiling...
fnyt12.cpp
g:\cpp\fnyt12\fnyt12.cpp(12) : warning C4288: nonstandard extension used :
'i' : loop control variable declared in the for-loop is used outside the
for-loop scope; it conflicts with the declaration in the outer scope
g:\cpp\fnyt12\fnyt12.cpp(9) : definition of 'i' used
g:\cpp\fnyt12\fnyt12.cpp(7) : definition of 'i' ignored

Build log was saved at "file://g:\cpp\fnyt12\Debug\BuildLog.htm"
fnyt12 - 0 error(s), 1 warning(s)


---------------------- Done ----------------------

Build: 1 succeeded, 0 failed, 0 skipped


<æld-gamle scope regel/>

<rigtig scope regel>
------ Build started: Project: fnyt12, Configuration: Debug Win32 ------

Compiling...
fnyt12.cpp
g:\cpp\fnyt12\fnyt12.cpp(12) : warning C4258: 'i' : definition from the for
loop is ignored; the definition from the enclosing scope is used
g:\cpp\fnyt12\fnyt12.cpp(9) : definition of 'i' ignored
g:\cpp\fnyt12\fnyt12.cpp(7) : definition of 'i' used

Build log was saved at "file://g:\cpp\fnyt12\Debug\BuildLog.htm"
fnyt12 - 0 error(s), 1 warning(s)


---------------------- Done ----------------------

Build: 1 succeeded, 0 failed, 0 skipped
<rigtig scope regel/>



Venlig hilsen

Mogens Hansen



Per Abrahamsen (07-02-2002)
Kommentar
Fra : Per Abrahamsen


Dato : 07-02-02 10:45

igorr@ifi.uio.no (Igor V. Rafienko) writes:

> Rett meg
> om jeg tar feil, men var det ikke slik at skopet til variable
> introdusert i if-setninger var nettopp if-setninger?.

Jo, det var begrundelsen for at endelig at få for-scopet til at opføre
sig fornuftigt.

> Det man _burde_
> ha gjort var å lage en opsjon til kompilatoren som tolket skopet den
> ene eller den andre veien og såsnart standarden kom ut bruke
> standarden som "default" modus.

Jeg kan faktisk lide den måde g++ gjorde det, de skiftede til de nye
regler så snart kommiteen besluttede dem, men sørgede samtidig for at
kode der var legal med de gamle regler og illegal med de nye fortsat
ville oversætte (med en advarsel). Plus at de selvfølgelig havde (og
har) en option til at bruge de gamle regler.


Anders Borum (07-02-2002)
Kommentar
Fra : Anders Borum


Dato : 07-02-02 11:31

"Per Abrahamsen" <abraham@dina.kvl.dk> skrev i en meddelelse
news:rju1stzkv5.fsf@ssv2.dina.kvl.dk...
> igorr@ifi.uio.no (Igor V. Rafienko) writes:
[klip]
> > Det man _burde_
> > ha gjort var å lage en opsjon til kompilatoren som tolket skopet den
> > ene eller den andre veien og såsnart standarden kom ut bruke
> > standarden som "default" modus.

Microsoft har /næsten/ gjort dette. Den før-omtalte /Za vil jo som sagt få
skopet til at opføre sig moderne. Denne switch er ikke slået til normalt,
fordi windows-headerne ikke kan tåle det. Men hvis man ønsker at skrive
portabel c++-kode kan man alligevel ikke bruge win32-api'en.
I praksis vil man have sin windows-specfikke kildekode for sig og den
platform-uafhængige for sig. Så kan man bruge /Za på de platform-
uafhængige filer. Det dør man vel næppe af.

Man dør selvfølgelig heller ikke af at den gamle kode fra starthalvfemserne
ikke kan oversætte længere uden en compiler-switch. Men jeg finder det
stadig meget sympatisk at MS har valgt at prioritere bagud-kompatibilitet.

> Jeg kan faktisk lide den måde g++ gjorde det, de skiftede til de nye
> regler så snart kommiteen besluttede dem, men sørgede samtidig for at
> kode der var legal med de gamle regler og illegal med de nye fortsat
> ville oversætte (med en advarsel). Plus at de selvfølgelig havde (og
> har) en option til at bruge de gamle regler.

Ja. gcc's løsning kan nok glæde mange. Jeg kan ikke tælle hvor mange
gange jeg har smilt (lettet og lidt lykkelig) af advarslen:
: name lookup of `i' changed for new ANSI `for' scoping
: using obsolete binding at `i'

Hilsen Anders




Bertel Lund Hansen (07-02-2002)
Kommentar
Fra : Bertel Lund Hansen


Dato : 07-02-02 12:57

Anders Borum skrev:

>Men jeg finder det stadig meget sympatisk at MS har valgt
>at prioritere bagud-kompatibilitet.

Det begrunder ikke at de ikke gør det på den smarte måde som GCC
åbenbart har gjort det.

--
Bertel
http://lundhansen.dk/bertel/   FIDUSO: http://fiduso.dk/

Igor V. Rafienko (07-02-2002)
Kommentar
Fra : Igor V. Rafienko


Dato : 07-02-02 13:33

[ Anders Borum ]

[ snip ]

> Microsoft har /næsten/ gjort dette.


"An almost ISO compliant compiler will almost leverage your codebase
to today's standards". Ja, særlig :)

Håkon Wium Lie holdt et foredrag på Ifi om Opera for en god stund
tilbake. De jobbet veldig hardt for å presse ned Opera på 1 diskett.
Til slutt vokste prosjektet for mye og det var veldig synd fordi
slagordet "Opera, almost fits on one floppy" ikke var fullt så bra med
"almost".


> Den før-omtalte /Za vil jo som sagt få skopet til at opføre sig
> moderne. Denne switch er ikke slået til normalt, fordi
> windows-headerne ikke kan tåle det.


Gid det var så vel -- Mogens Hansen gav jo et "hello, world" eksempel
som trynet miserabelt med /Za og da brukte han kun <iostream>.


> Men hvis man ønsker at skrive portabel c++-kode kan man alligevel
> ikke bruge win32-api'en. I praksis vil man have sin
> windows-specfikke kildekode for sig og den platform-uafhængige for
> sig. Så kan man bruge /Za på de platform- uafhængige filer. Det dør
> man vel næppe af.


Se <URL:news:a3s6e3$9af$1@news.cybercity.dk>


> Man dør selvfølgelig heller ikke af at den gamle kode fra
> starthalvfemserne ikke kan oversætte længere uden en
> compiler-switch. Men jeg finder det stadig meget sympatisk at MS har
> valgt at prioritere bagud-kompatibilitet.


Eh... det aller _viktigste_ for en kompilator er å implementere
språket riktig. Bakoverkompatibilitet på bekostning av det å være i
henhold til språkdefinisjonen slår meg som et _usedvanlig_ dårlig
valg.

Det er uheldig at tolkningen av skopreglene har forandret seg. Men når
standarden først har sagt "slik er det", så _skal_ en kompilator følge
etter. Bakoverkompatibilitet som strider mot standarden bør tilbys
vha. opsjoner som ikke er slått på "ut av esken".





ivr
--
Good news everyone: I've taught the toaster to feel love
         Pr. Farnsworth, Futurama

Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408925
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste