By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,078 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,078 IT Pros & Developers. It's quick & easy.

Just a dodgy compiler?

P: n/a

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
Mar 3 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
> std::wcslen("monkey");
Typo, that should be a wide literal:
std::wcslen( L"monkey" );
-Tomás

Mar 3 '06 #2

P: n/a
On 2006-03-03, Tomás <NU**@NULL.NULL> wrote:

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++.

--
Neil Cerutti
Mar 3 '06 #3

P: n/a
* Neil Cerutti:
On 2006-03-03, Tomás <NU**@NULL.NULL> wrote:

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++.


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].
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 3 '06 #4

P: n/a
Neil Cerutti wrote:
On 2006-03-03, Tomás <NU**@NULL.NULL> wrote:

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++.


wcslen is the wchar_t equivalent of strlen. And I believe it's in both
C90 and C++98.
Mar 3 '06 #5

P: n/a
On 2006-03-03, Alf P. Steinbach <al***@start.no> wrote:
* Neil Cerutti:
On 2006-03-03, Tomás <NU**@NULL.NULL> wrote:

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++.


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.

--
Neil Cerutti
The church will host an evening of fine dining, superb
entertainment, and gracious hostility. --Church Bulletin
Blooper
Mar 3 '06 #6

P: n/a
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?

Mar 3 '06 #7

P: n/a

zeior wrote:
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.

Mar 3 '06 #8

P: n/a
* 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.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 3 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.