strtol问题 [英] strtol question

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

问题描述

不是:


char s [] =" - 4" ;;

char * endptr;


strtol(s,& endptr,0);


应该返回0并将endptr设置为s?我已经遇到了一个实现

(不是gcc,gcc做我期望的)返回LONG_MIN !!我害怕

看看它对endptr做了什么:-)


-nrk。


-

删除电子邮件的devnull

Isn''t:

char s[] = "--4";
char *endptr;

strtol(s, &endptr, 0);

supposed to return 0 and set endptr to s? I have run into an implementation
(not gcc, gcc does what I expect) that is returning LONG_MIN!! I am afraid
to see what it did to endptr :-)

-nrk.

--
Remove devnull for email

推荐答案

nrk< ra ********* @ devnull.verizon达网络>写道:
nrk <ra*********@devnull.verizon.net> wrote:
不是:

char s [] =" - 4" ;;
char * endptr;

strtol(s,& endptr,0);

应该返回0并将endptr设置为s?


是的。

我已经遇到了一个实现
(不是gcc,gcc做我期望的)返回LONG_MIN !!


只有转换后的值_is_为LONG_MIN,或者在
之外,才允许长期和负数的范围。在这种情况下,没有转换的

值,因为两者都没有 - 4。也不是-4以一个整数常量开始。

我害怕看到它对endptr做了什么: - )
Isn''t:

char s[] = "--4";
char *endptr;

strtol(s, &endptr, 0);

supposed to return 0 and set endptr to s?
Yes.
I have run into an implementation
(not gcc, gcc does what I expect) that is returning LONG_MIN!!
That''s only allowed if the converted value _is_ LONG_MIN, or is outside
the range of long and negative. In this case, there is no converted
value, since neither "--4" nor "-4" starts with an integer constant.
I am afraid to see what it did to endptr :-)




我很好看它做了什么......这是什么实现,顺便说一句?


Richard



I''m _curious_ to see what it did... Which implementation is this, btw?

Richard




" ; NRK" < RA ********* @ devnull.verizon.net>在消息中写道

新闻:iy *************** @ nwrddc03.gnilink.net ...

"nrk" <ra*********@devnull.verizon.net> wrote in message
news:iy***************@nwrddc03.gnilink.net...
不是:

char s [] =" - 4";
char * endptr;

strtol(s,& endptr,0);

应该返回0并将endptr设置为s?我遇到了返回LONG_MIN的
实现(不是gcc,gcc做我期望的)!我是
害怕看到它对endptr做了什么: - )
Isn''t:

char s[] = "--4";
char *endptr;

strtol(s, &endptr, 0);

supposed to return 0 and set endptr to s? I have run into an implementation (not gcc, gcc does what I expect) that is returning LONG_MIN!! I am afraid to see what it did to endptr :-)




第三个值应该是你希望它转换成的基数。<我的发行版上的
手册页说如果值

下溢并且它将设置errno,它可以返回LONG_MIN。所以也许一个base-0请求是

下溢?


Tom



The third value is supposed to be the base you want it converted in. The
man pages on my distro say that it can return LONG_MIN if the value
underflows and it will set errno. So maybe a base-0 request is an
underflow?

Tom


" Tom圣丹尼斯 < to*@securescience.net>写道:
"Tom St Denis" <to*@securescience.net> wrote:
" nrk" < RA ********* @ devnull.verizon.net>在消息中写道
新闻:iy *************** @ nwrddc03.gnilink.net ...
"nrk" <ra*********@devnull.verizon.net> wrote in message
news:iy***************@nwrddc03.gnilink.net...
strtol(s,& endptr, 0);
strtol(s, &endptr, 0);


第三个值应该是你想要它转换的基础。我的发行版上的
手册页说如果值
下溢它可以返回LONG_MIN它会设置errno。那么也许一个基数为0的请求是下溢?


The third value is supposed to be the base you want it converted in. The
man pages on my distro say that it can return LONG_MIN if the value
underflows and it will set errno. So maybe a base-0 request is an
underflow?




或许不是。也许最好在制作之前阅读标准,然后在公共场合做出错误的猜测。如果您已经这样做了,那么您已经知道

,基数为0是对

实现的完全明确定义的请求,以便从字符串中找出基数本身。


Richard



Or maybe not. And maybe it''s better to read the Standard before making
wild-asses wrong guesses in public. If you had done so, you''d have known
that a base of 0 is a perfectly well defined request to the
implementation to figure out the base from the string itself.

Richard


这篇关于strtol问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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