函数返回* char [英] functions returning *char

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

问题描述




我想知道,可以安全地假设任何返回

a * char的函数都会返回一个以NULL结尾的字符串吗?或者功能

是否总是明确提到这一点(以及那些不会返回的那些

null终止字符串?)


Rick

Hi,

I was wondering, can it be safely assumed that any function that returns
a *char will return a NULL terminated string? Or does the function
explicitly mention this always (and the ones that don''t do not return
null terminated strings?)

Rick

推荐答案

Rick< rrquick @ nospam-com>潦草地说:
Rick <rrquick@nospam-com> scribbled the following:

我想知道,可以安全地假设任何返回
a * char的函数都会返回一个以NULL结尾的字符串吗?或者该函数是否总是明确地提到这个(并且那些不会返回
空终止的字符串?)
Hi, I was wondering, can it be safely assumed that any function that returns
a *char will return a NULL terminated string? Or does the function
explicitly mention this always (and the ones that don''t do not return
null terminated strings?)




否,从仅仅看到一个函数返回一个char *,你不能说

是否会返回一个以null结尾的字符串。它可能,或者

它可能不会。


-

/ - Joona Palaste(pa ***** @ cc.helsinki.fi)-------------芬兰-------- \

\-- http://www.helsinki.fi/~palaste ------------ ---------规则! -------- /

肯定很有钱和小鸡。

- Beavis和Butt-head



No, from merely seeing that a function returns a char*, you can''t say
anything whether it will return a null-terminated string. It might, or
it might not.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head


Rick< rrquick @ nospam-com>在新闻中写道:3f ****** @ clarion.carno.net.au:
Rick <rrquick@nospam-com> wrote in news:3f******@clarion.carno.net.au:
我在想,可以安全地假设任何返回的函数
a * char将返回一个以NULL结尾的字符串?或者该函数是否总是明确地提到这个(并且那些不会返回
空终止的字符串?)
I was wondering, can it be safely assumed that any function that returns
a *char will return a NULL terminated string? Or does the function
explicitly mention this always (and the ones that don''t do not return
null terminated strings?)




否,我不会假设char * func()返回一个C字符串(null终止)。

如果你有一块内存你想要返回指针怎么办?你需要读取函数描述才能知道它是否返回null

终止字符串。


-

- 马克 - >

-



No, I would not assume char *func() returns a C string (null terminated).
What if you have a block of memory you want to return a pointer to? You
need to read the function description to know if it returns a null
terminated string.

--
- Mark ->
--


问候。


In文章< 3f ****** @ clarion.carno.net.au>,Rick写道:
Greetings.

In article <3f******@clarion.carno.net.au>, Rick wrote:
我想知道,可以安全地假设任何返回的函数
a * char将返回一个以NULL结尾的字符串?或者该函数是否总是明确地提到这个(并且那些不会返回
空终止的字符串?)
I was wondering, can it be safely assumed that any function that returns
a *char will return a NULL terminated string? Or does the function
explicitly mention this always (and the ones that don''t do not return
null terminated strings?)




Nope 。返回* char的函数甚至可能根本不会向字符串返回指向

的东西(即,当它返回指针值NULL时)。总是

阅读函数的文档(或代码本身,如果没有

文档),以确定可以得出关于
$的结论b $ b返回值。


请注意,您似乎混淆了一些关于

字符串和指针的术语 - NULL(以大写字母表示)到特定的

指针值表示指针没有指向

特定的任何内存。另一方面,null表示null。在短语null-terminated

string中指的是''\ 0''(在ASCII中命名为NUL,当然,你可能没有使用ASCII系统的
),它在C中用作

字符串结束标记。字符''\ 0''和指针值NULL可能

技术上从人类的角度来看具有相同的积分值,但是

因为它们是不同类型的,他们不能被视为平等或使用

(代码或自然语言)可互换。


问候,

特里斯坦


-

_

_V.-o Tristan Miller [en,(fr,de,ia) ]><空间有限

/ |` - '' - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =<> ;在ha句中,所以很难

(7_ \\ http://www.nothingisreal.com/ ><完成你的工作



Nope. A function returning a *char might not even return something pointing
to a string at all (i.e., when it returns the pointer value NULL). Always
read the function''s documentation (or the code itself, if there is no
documentation) to determine what conclusions can be drawn regarding the
return value.

Note that you appear to be confusing some terminology with respect to
strings and pointers -- NULL (in capital letters) refers to a specific
pointer value denoting that the pointer does not point to any memory in
particular. On the other hand, the "null" in the phrase "null-terminated
string" refers to the character ''\0'' (named NUL in ASCII, though of course
you might not be using an ASCII system), which is used in C as an
end-of-string marker. The character ''\0'' and the pointer value NULL might
technically have the same integral value from a human''s point of view, but
as they are of different types they cannot be considered equal or used
(either in code or in natural language) interchangeably.

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-'' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it''s hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you


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

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