 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Stefan Ram Guest
|
Posted: Fri Mar 02, 2007 10:12 am Post subject: std |
|
|
Das folgende Programm wird von Comeau akzeptiert.
#include <cctype>
int main(){ tolower( 0 ); }
Sollte es nicht statt dessen folgendes melden?
line 1: error: identifier "tolower" is undefined
int main(){ tolower( 0 ); }
^
Unter Dev-C++ 4.9.9.0 (und wahrscheinlich auch .1; basierend
auf mingw und damit gcc) gibt folgendes Programm »65« aus,
während ich »97« erwartet hätte:
#include <iostream>
#include <ostream>
#include <cctype>
int tolower( int const x ){ return x; }
int main(){ ::std::cout << ::std::tolower( 65 ) << '\n'; } |
|
| Back to top |
|
 |
Stefan Ram Guest
|
Posted: Fri Mar 02, 2007 10:12 am Post subject: Re: std |
|
|
ram (AT) zedat (DOT) fu-berlin.de (Stefan Ram) writes:
| Quote: | int tolower( int const x ){ return x; }
|
Aha, dieser Name ist wohl auch ohne »::std::« davor in C++
reserviert, da er aus C stammt. |
|
| Back to top |
|
 |
James Kanze Guest
|
Posted: Fri Mar 02, 2007 3:53 pm Post subject: Re: std |
|
|
On Mar 2, 6:08 am, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
| Quote: | Das folgende Programm wird von Comeau akzeptiert.
#include <cctype
int main(){ tolower( 0 ); }
Sollte es nicht statt dessen folgendes melden?
line 1: error: identifier "tolower" is undefined
int main(){ tolower( 0 ); }
^
|
Es soll, laut der Norm. Soweit ich weiß, gibt es keine
Implementierung der Bibliothek, die in dieser Hinsicht konform
ist.
| Quote: | Unter Dev-C++ 4.9.9.0 (und wahrscheinlich auch .1; basierend
auf mingw und damit gcc) gibt folgendes Programm »65« aus,
während ich »97« erwartet hätte:
#include <iostream
#include <ostream
#include <cctype
int tolower( int const x ){ return x; }
int main(){ ::std::cout << ::std::tolower( 65 ) << '\n'; }
|
Laut der neusten Draft ist der Name tolower reserviert in beide
::std:: und ::. Auch früher was es undefiniert, ob die Namen in
<c...> »extern "C"« sind, oder nicht. Falls tolower »extern "C"«
ist (der Fall in allen Bibliotheken, die ich kenne), dann hast
du undefiniertes Verhalten:
(§7.5/4):
A function can be declared without a linkage
specification after an explicit linkage specification
has been seen; the linkage explicitly specified in the
earlier declaration is not affected by such a function
declaration.
(§7.5/5):
Two declarations for a function with C language linkage
with the same function name (ignoring the namespace
names that qualify it) that appear in different
namespace scopes refer to the same function.
Was zusammen bedeuten, dass deine »tolower« eine Definition von
»extern "C" std::tolower« ist; ein Versuch aber, eine Funktion
der Standard-Bibliothek umzudefinieren, ist undefiniertes
Verhalten.
Ins Gesamt kann man sagen, daß (verständlicherweise) namespace
und »extern "C"« passen nicht zusammen. Ich selber benutze nicht
die <c...>-Includes, weil ich damit nicht genau weiß, was ich
habe; mit <ctype.h> is alles klar(er). (Damit schreibe ich auch
::tolower, und nicht ::std::tolower.)
--
James Kanze (GABI Software) email:james.kanze (AT) gmail (DOT) com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 |
|
| Back to top |
|
 |
Ole Hinz Guest
|
Posted: Sat Mar 03, 2007 1:27 am Post subject: Re: std |
|
|
Stefan Ram wrote:
| Quote: | Das folgende Programm wird von Comeau akzeptiert.
#include <cctype
int main(){ tolower( 0 ); }
Sollte es nicht statt dessen folgendes melden?
line 1: error: identifier "tolower" is undefined
int main(){ tolower( 0 ); }
^
|
Hallo Stefan
Das Problem kenne ich auch. Ich übersetze teilweise mit GCC (als
cross-compiler) und VC6.0.
Der GCC hätte gerne std::tolower, während der VC6.0 nur ::tolower möchte.
Als "Ausweg" bleibt eigentlich nur die alten C-Header einbinden. Da weiß
man wenigstens, dass es im globalen Namespace landet.
Gruß
Ole Hinz
--
http://www.ole-hinz.de |
|
| Back to top |
|
 |
Stefan Reuther Guest
|
Posted: Sat Mar 03, 2007 10:47 pm Post subject: Re: std |
|
|
Ole Hinz wrote:
| Quote: | Der GCC hätte gerne std::tolower, während der VC6.0 nur ::tolower möchte.
Als "Ausweg" bleibt eigentlich nur die alten C-Header einbinden. Da weiß
man wenigstens, dass es im globalen Namespace landet.
|
Ich verwende bei sowas '#include <cctype>' nebst 'using namespace std'
selektiv an den Stellen, wo es benötigt wird (also i.a. eine Handvoll
Funktionen eines Moduls). Damit erwischt man eigentlich alle mir
bekannten kaputten Implementationen (Linux mit libc5 hätte gerne
'tolower' ohne '::', weil es ein Makro ist. Borland C++ hat, wenn man
mit Optimierung übersetzt, das gleiche Problem mit den strXXX- und
memXXX-Funktionen.)
Stefan |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|