什么是strdup回归 [英] what does strdup return

查看:86
本文介绍了什么是strdup回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




已知strdup()返回一个char *类型,但有时候

后面的代码会生成警告消息。


char * x = ...

char * p = strdup(x);


你必须改变它要


char * p =(char *)strdup(x);


为什么?

Hi,

It''s known that strdup() returns a char* type, but sometimes the
following code generates warning messages.

char *x = ...
char *p = strdup(x);

You must change it to

char *p = (char*) strdup(x);

why?

推荐答案

10月2日,10:56,thomas< FreshTho ... @ gmail.comwrote:
On 2 Oct, 10:56, thomas <FreshTho...@gmail.comwrote:

It'众所周知,strdup()返回一个char *类型,
It''s known that strdup() returns a char* type,



strdup()在C标准中没有提及它是在一个保留的

引导名称空间;所以你不能自己定义。

所以我们对它一无所知。

strdup() isn''t mentioned in the C Standard and it''s in a reserved
namespace to boot; so you can''t define it yourself.
So we don''t really know anything about it.


但有时

以下代码会生成警告信息。


char * x = ...

char * p = strdup( x);


您必须将其更改为


char * p =(char *)strdup(x);


为什么?
but sometimes the
following code generates warning messages.

char *x = ...
char *p = strdup(x);

You must change it to

char *p = (char*) strdup(x);

why?



我怀疑strdup()的范围没有原型。

string.h可能不会声明它(我不是确保它允许在conmforming模式下声明




你需要提出更多的实施问题

某些指导。

-

Nick Keighley


服务器机房应该不友好!他们应该看起来很危险,他们应该感到非常寒冷,他们应该莫名其妙地吵闹。

如果你可以安排燃烧晶体管的气味,这很好

也是。

如果有的话,我宁愿看到设计在黑暗中的机架式服务器

预感

颜色搭配很多金属尖刺都伸出来了。

Mike Sphar(新闻// alt.sysadmin.recovery)

I suspect there is no prototype in scope for strdup().
string.h may not declare it (I''m not sure it''s allowed to declare
it, in conmforming mode).

You need to ask the question of your implementation for more
certain guidance.
--
Nick Keighley

Server rooms should be unfriendly! They should look dangerous,
they should be uncomfortably cold, they should be inexplicably noisy.
If you can arrange for the smell of burning transistors, that''s good
too.
If anything, I''d rather see rackmounted servers designed in dark
foreboding
colors with lots of metal spikes sticking out of them.
Mike Sphar (on news//alt.sysadmin.recovery)


文章< c2 **********************************@25g2000hsk.g ooglegroups.com> ;,

thomas< Fr ********* @ gmail.comwrote:
In article <c2**********************************@25g2000hsk.g ooglegroups.com>,
thomas <Fr*********@gmail.comwrote:

>众所周知,strdup()返回一个char *类型,但有时
以下代码会生成警告消息。

char * x = ...
char * p = strdup(x);
你必须把它改成

char * p =(char *)strdup(x);

为什么?
>It''s known that strdup() returns a char* type, but sometimes the
following code generates warning messages.

char *x = ...
char *p = strdup(x);

You must change it to

char *p = (char*) strdup(x);

why?



因为您尚未声明strdup(),并且未包含

声明的标头。您还显然没有以某种模式运行编译器

,它抱怨未声明的函数。


修复添加一个演员的问题在系统上不能可靠地运行

其中指针比整数长,或指针和整数的返回

约定不同。 br />

- 理查德

-

请记得提及我/你留下的录音带。

Because you have not declared strdup(), and not included a header that
declares it. You have also apparently not run your compiler in a mode
where it complains about undeclared functions.

"Fixing" the problem by adding a cast won''t work reliably on systems
where pointers are longer than integers, or where the return
conventions for pointers and integers are different.

-- Richard
--
Please remember to mention me / in tapes you leave behind.


10月2日下午1:05,Nick Keighley< nick_keighley_nos ... @ hotmail.com>

写道:
On Oct 2, 1:05 pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:

10月2日,10:56,thomas< FreshTho ... @ gmail.comwrote:
On 2 Oct, 10:56, thomas <FreshTho...@gmail.comwrote:

已知strdup ()返回一个char *类型,
It''s known that strdup() returns a char* type,



strdup()在C标准中没有提及它是在保留的
$ b要启动的$ b命名空间;所以你不能自己定义它。


strdup() isn''t mentioned in the C Standard and it''s in a reserved
namespace to boot; so you can''t define it yourself.



如果你不包括< string.h>

You can if you don''t include <string.h>


但有时候代码后面的

会生成警告消息。
but sometimes the
following code generates warning messages.


char * x = ...

char * p = strdup(x);
char *x = ...
char *p = strdup(x);


您必须将其更改为
You must change it to


char * p =( char *)strdup(x);
char *p = (char*) strdup(x);


为什么?
why?



我怀疑strdup()的范围没有原型。

string.h可能不会声明它(我不是确定它允许在conmforming模式下声明

它。


I suspect there is no prototype in scope for strdup().
string.h may not declare it (I''m not sure it''s allowed to declare
it, in conmforming mode).



这是允许的,因为正如你所说,strdup是实现命名空间。

It is allowed, since as you said, strdup is implementation namespace.


这篇关于什么是strdup回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆