包含标题:< X>,< X.h>和全局命名空间

包含标题:< X>,< X.h>和全局命名空间

问题描述:




以下程序无法在MS VC ++或Bloodshed Dev-C ++上编译


#include< iostream>


int strlen(const char * in)

{

int count = 0;

while(* in ++)count ++;

返回计数;

}


int main()

{

std :: cout<< 字符串长度\hey diddle diddle \是;

std :: cout<< strlen(hey diddle diddle)<< ''\ n'';

}

我一直认为使用< iostream>而不是< iostream.h>将

保留在全局命名空间之外的标准库定义。我在这个假设中是不是
不正确,或者这两个编译器真的很糟糕

那么糟糕? TIA

Hi

The following program doesn''t compile on MS VC++ or Bloodshed Dev-C++

#include <iostream>

int strlen(const char *in)
{
int count=0;
while (*in++) count++;
return count;
}

int main()
{
std::cout << "the length of string \"hey diddle diddle\" is ";
std::cout << strlen("hey diddle diddle") << ''\n'';
}
I always thought that using <iostream> rather than <iostream.h> would
keep standard library definitions out of the global namespace. Am I
incorrect in this assumption, or do those two compilers really suck
that bad? TIA



" Santiago de Compostela" &LT; SA ********* @ yahoo.com&GT;写道:

"Santiago de Compostela" <sa*********@yahoo.com> wrote:
以下程序无法在MS VC ++或Bloodshed Dev-C ++上编译

#include< iostream>

int strlen(const char * in)
{
int count = 0;
while(* in ++)count ++;
return count;
}

int main()
{
std :: cout<< 字符串长度\hey diddle diddle \是;
std :: cout<< strlen(hey diddle diddle)<< ''\ n'';
}

我一直认为使用< iostream>而不是< iostream.h>将标准库定义保留在全局命名空间之外。我在这个假设中是不正确的,还是这两个编译器确实很糟糕? TIA
The following program doesn''t compile on MS VC++ or Bloodshed Dev-C++

#include <iostream>

int strlen(const char *in)
{
int count=0;
while (*in++) count++;
return count;
}

int main()
{
std::cout << "the length of string \"hey diddle diddle\" is ";
std::cout << strlen("hey diddle diddle") << ''\n'';
}
I always thought that using <iostream> rather than <iostream.h> would
keep standard library definitions out of the global namespace. Am I
incorrect in this assumption, or do those two compilers really suck
that bad? TIA




对于它的价值,Comeau也拒绝它:


Comeau C / C ++ 4.3.3 (2003年8月6日15:13:37)ONLINE_EVALUATION_BETA1

版权所有1988-2003 Comeau Computing。保留所有权利。

模式:严格错误C ++


" ComeauTest.c",第3行:错误:无法超载功能区分

返回

类型单独

int strlen(const char * in)

^

1错误在ComeauTest.c的汇编中检测到。


对于它的价值,它通常被认为是确定哪个好的形式
$ b $您正在使用的b版本的
编译器。哪个版本的VC ++?并且Dev-C ++不是一个

编译器,它只是一个运行minGW的IDE,它是gcc的一个端口。我不知道是否

Dev-C ++

包含最新版本的minGW - 你可以获得gcc的beta端口3.4

来自mingw.com。


致敬,

Tom




For what it''s worth, Comeau rejects it as well:

Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 3: error: cannot overload functions distinguished by
return
type alone
int strlen(const char *in)
^
1 error detected in the compilation of "ComeauTest.c".

For what it''s worth, it''s usually considered good form to identify which
version of the
compiler you''re using. Which version of VC++? And Dev-C++ isn''t a
compiler, it''s
just an IDE that runs minGW, which is a port of gcc. I don''t know whether
Dev-C++
includes the latest version of minGW - you can get a beta port of gcc 3.4
from mingw.com.

Best regards,

Tom



Santiago de Compostela写道:
Santiago de Compostela wrote:


以下程序无法在MS VC ++或Bloodshed Dev-C ++上编译/>
#include< iostream>
int strlen(const char * in)
{int / count = 0;
while(* in ++ )count ++;
返回计数;
}
int main()
{
std :: cout<< 字符串长度\hey diddle diddle \是;
std :: cout<< strlen(hey diddle diddle)<< ''\ n'';
}

我一直认为使用< iostream>而不是< iostream.h>将标准库定义保留在全局命名空间之外。我在这个假设中是不正确的,还是这两个编译器确实很糟糕? TIA
Hi

The following program doesn''t compile on MS VC++ or Bloodshed Dev-C++

#include <iostream>

int strlen(const char *in)
{
int count=0;
while (*in++) count++;
return count;
}

int main()
{
std::cout << "the length of string \"hey diddle diddle\" is ";
std::cout << strlen("hey diddle diddle") << ''\n'';
}
I always thought that using <iostream> rather than <iostream.h> would
keep standard library definitions out of the global namespace. Am I
incorrect in this assumption, or do those two compilers really suck
that bad? TIA




VC ++ 6(可能是以前的版本)没有把C库

函数放在命名空间std中。我不知道以后的版本,或者关于

Bloodshed Dev-C ++。


Alan



VC++6 (and presumably previous versions) don''t put the C library
functions in namespace std. I don''t know about later versions, or about
Bloodshed Dev-C++.

Alan


Santiago de Compostela写道:
Santiago de Compostela wrote:


以下程序无法在MS VC ++或Bloodshed Dev-C ++上编译

#include< iostream>
int strlen(const char * in)
{int / count = 0;
while(* in ++)count ++;
返回计数;
}
int main()
{
std :: cout<< 字符串长度\hey diddle diddle \是;
std :: cout<< strlen(hey diddle diddle)<< ''\ n'';
}

我一直认为使用< iostream>而不是< iostream.h>将标准库定义保留在全局命名空间之外。我在这个假设中是不正确的,还是这两个编译器确实很糟糕? TIA
Hi

The following program doesn''t compile on MS VC++ or Bloodshed Dev-C++

#include <iostream>

int strlen(const char *in)
{
int count=0;
while (*in++) count++;
return count;
}

int main()
{
std::cout << "the length of string \"hey diddle diddle\" is ";
std::cout << strlen("hey diddle diddle") << ''\n'';
}
I always thought that using <iostream> rather than <iostream.h> would
keep standard library definitions out of the global namespace. Am I
incorrect in this assumption, or do those two compilers really suck
that bad? TIA




是的,你对这个假设是正确的,这是一个糟糕的实现

问题。事实上,您可以将其报告为MINGW开发团队中的缺陷

(在他们的邮件列表或其他内容中)。


解决方法是定义您的strlen()在另一个命名空间,一个东西

你*应该*在定义标准库的新版本时做什么

设施。




Ioannis Vranos




Yes you are right about the assumption, this is a bad implementation
issue. In fact you can report it as a defect in MINGW development team
(in their mailing list or something).

A work-around is to define your strlen() in another namespace, a thing
you *should* do anyway when defining new versions of standard library
facilities.


Regards,

Ioannis Vranos