strcpy和strcat的返回类型 [英] strcpy and strcat's return type

查看:82
本文介绍了strcpy和strcat的返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




为什么strcpy和strcat(以及某些非标准的
实现中的strupr和strlwr)返回一个char *?当然这些逻辑(和DMA安全)

)返回类型将无效?


谢谢,


James McLaughlin。

解决方案

----- BEGIN PGP签名消息-----

哈希:SHA1

ze ********** ****@yahoo.com 写道:



为什么strcpy和strcat(以及某些非标准
实现中的strupr和strlwr) )返回一个char *?当然这些逻辑(和DMA安全)
返回类型是无效的?




为什么strcat()返回一个void *,当它的两个参数都是

char *,并且函数被定义为处理字符串?


strcpy()也是如此:为什么你认为它应该返回无效

*而不是char *?

ISTM,因为两个函数

a)取char *作为参数(而不是void *),

b)处理char *数据,并且

c)创建char *指针最好描述的结果,

两个函数/应该/返回char *指向它们已生成的结果的指针。


- -


Lew Pitcher,IT专家,企业数据系统

企业技术解决方案,道明银行金融集团


(此处表达的意见是我自己的,不是我的意见雇主的)

-----开始PGP签名-----

V ersion:GnuPG v1.2.4(MingW32)

iD8DBQFC5ickagVFX4UWr64RAmWKAJ9ymd + jL7wIqVGgrHNTo1 98BnxJDgCgrXyr

BGAvh0N9wubb8W9NJLmfxIA =

= 6TrQ

-----结束PGP SIGNATURE -----


Lew Pitcher:

泽************** @ yahoo.com


....

为什么strcpy和strcat(以及某些非标准
实现中的strupr和strlwr)返回char *?当然这些逻辑(和DMA安全)
返回类型是无效的吗?



为什么strcat()返回void *,当它们都是'的论点是
char *,函数被定义为处理字符串?




他说无效,不是无效*。并回答实际问题:我认为,

他们返回char *以允许这样的东西


返回strcat(strcpy(buf,path),file );


Jirka


Jirka Klaue写道:


Lew Pitcher:< blockquote class =post_quotes> ze ************** @ yahoo.com


...

为什么strcpy和strcat(以及某些非标准的strpr和strlwr
implementation)返回一个char *?当然这些逻辑(和DMA安全)
返回类型是无效的吗?



为什么strcat()返回void *,当它们都是'的论点是
char *,函数被定义为处理字符串?



他说无效,不是无效*。并回答实际问题:我认为,
他们返回char *以允许返回strcat(strcpy(buf,path),file);




此外,原本没有虚函数这样的东西吗? (我

知道我在没有无效的平台上工作。)


-

+ ----- -------------------- + -------------------- + -------- --------------------- +

| Kenneth J. Brody | www.hvcomputer.com | |

| kenbrody / at\spamcop.net | www.fptech.com | #include< std_disclaimer.h> |

+ ------------------------- + -------------- ------ + ----------------------------- +

不要给我发电子邮件:< mailto:Th ************* @ gmail.com>


Hi,

Why do strcpy and strcat (and strupr and strlwr in some nonstandard
implementations) return a char*? Surely the logical (and DMA-safe)
)return type for these would have been void??

Thanks,

James McLaughlin.

解决方案

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ze**************@yahoo.com wrote:

Hi,

Why do strcpy and strcat (and strupr and strlwr in some nonstandard
implementations) return a char*? Surely the logical (and DMA-safe)
)return type for these would have been void??



Why should strcat() return a void *, when both of it''s arguments are
char *, and the function is defined as working on character strings?

The same goes for strcpy(): why do you think that it should return void
* rather than char *?
ISTM that, since both functions
a) take char * as arguments (and not void *),
b) work on char * data, and
c) create results best described by char * pointers,
both functions /should/ return char * pointers to the results that they
have generated.

- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer''s)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFC5ickagVFX4UWr64RAmWKAJ9ymd+jL7wIqVGgrHNTo1 98BnxJDgCgrXyr
BGAvh0N9wubb8W9NJLmfxIA=
=6TrQ
-----END PGP SIGNATURE-----


Lew Pitcher:

ze**************@yahoo.com:


....

Why do strcpy and strcat (and strupr and strlwr in some nonstandard
implementations) return a char*? Surely the logical (and DMA-safe)
)return type for these would have been void??



Why should strcat() return a void *, when both of it''s arguments are
char *, and the function is defined as working on character strings?



He said void, not void *. And to answer the actual question: I think,
they return char * to allow such things as

return strcat(strcpy(buf, path), file);

Jirka


Jirka Klaue wrote:


Lew Pitcher:

ze**************@yahoo.com:


...

Why do strcpy and strcat (and strupr and strlwr in some nonstandard
implementations) return a char*? Surely the logical (and DMA-safe)
)return type for these would have been void??



Why should strcat() return a void *, when both of it''s arguments are
char *, and the function is defined as working on character strings?



He said void, not void *. And to answer the actual question: I think,
they return char * to allow such things as

return strcat(strcpy(buf, path), file);



Besides, wasn''t there originally no such thing as a void function? (I
know I worked on platforms without "void".)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don''t e-mail me at: <mailto:Th*************@gmail.com>


这篇关于strcpy和strcat的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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