Just a dodgy compiler?

T

Tomás

This won't compile for me, it's saying "wcslen" isn't defined in the
"std" namespace:

#include <cwchar>

int main()
{
std::wcslen("monkey");
}


Just a dodgy compiler?

-Tomás
 
T

Tomás

std::wcslen("monkey");


Typo, that should be a wide literal:


std::wcslen( L"monkey" );


-Tomás
 
N

Neil Cerutti

This won't compile for me, it's saying "wcslen" isn't defined in the
"std" namespace:

#include <cwchar>

int main()
{
std::wcslen("monkey");
}


Just a dodgy compiler?

There's no such function in Standard C or C++.
 
A

Alf P. Steinbach

* Neil Cerutti:
There's no such function in Standard C or C++.

There is, and Tomás is using the right header to pull it in, and it
compiles with a conforming compiler.

There is a useful technique for library implementations that are
non-conforming wrt. to placing things in namespace std,

// File [wrapper/cwchar.h]
#ifndef WRAPPER_CWCHAR_H
#define WRAPPER_CWCHAR_H
#include <cwchar>

#ifdef MY_DODGY_COMPILER
namespace std{ using ::wcslen; }
#endif
#endif

then #include that file instead.

The naming of the wrapper header is not arbitrary; <string> would have
the wrapper [string.h], and <string.h> would have [string_h.h].
 
N

Neil Cerutti

* Neil Cerutti:

There is, and Tomás is using the right header to pull it in, and it
compiles with a conforming compiler.

Obviously, you're right. My standard-search algorithm was highly
impaired, as the function was not listed in the index, and that's the
only place I looked. Thanks.
 
Z

zeior

I'm pretty sure that according to the C++ standard (ISO/IEC 14882:2003)
wcslen is in the global namespace, not in std. Why do you think that
wcslen should be in namespace std?
 
R

roberts.noah

zeior said:
I'm pretty sure that according to the C++ standard (ISO/IEC 14882:2003)
wcslen is in the global namespace, not in std. Why do you think that
wcslen should be in namespace std?

Well, 17.4.1.1(2) states, "All library entities except macros, operator
new and operator delete are defined within the namespace std or
namespaces nested within namespace std."

21.4 classifies wcslen as a function so it isn't a macro and obviously
isn't new or delete.

Therefore, short of anything specifying otherwise I would have to
assume it is in namespace std and I can't find anything specifying
otherwise.
 
A

Alf P. Steinbach

* zeior:
I'm pretty sure that according to the C++ standard (ISO/IEC 14882:2003)
wcslen is in the global namespace, not in std.

You're wrong.
Why do you think that
wcslen should be in namespace std?

Because the standard says so. ;-)

In several places, but most relevant, in §17.4.1.2/4.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top