这回归UB? [英] Is this return UB ?

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

问题描述

这是返回UB吗?

int someFunt()

{

static int i = 0;

返回i ++;

}


我们想要的是第一次返回0,接下来的1等


有些想法吗?


谢谢!

Joe

WB2JQT


----------------------

我想让我的妻子去开一根棍子。

她学会了自己开扫帚。

Is this return UB ?
int someFunt ()
{
static int i = 0 ;

return i++ ;
}

WHat we want is the first time to return 0, next 1, etc

some thoughts ?

Thanks !
Joe
WB2JQT

----------------------
I tought my wife to drive a stick.
She learned to drive the broom all on her own.

推荐答案

达达说:
dada said:

这是返回UB吗?


int someFunt()

{

static int i = 0;


返回i ++;

}


我们想要的是第一次返回0,接下来的1等等
Is this return UB ?
int someFunt ()
{
static int i = 0 ;

return i++ ;
}

WHat we want is the first time to return 0, next 1, etc



这没关系,直到你达到INT_MAX。如果你不打算那么高,

没问题。


-

Richard Heathfield< http ://www.cpax.org.uk>

电子邮件:-www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

That''s fine, until you hit INT_MAX. If you don''t plan to get that high,
no problem.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


Richard Heathfield写道:
Richard Heathfield wrote:

dada说:

>>这是返回UB吗?

int someFunt()
{
static int i = 0;

返回i ++;
}

我们想要的是第一次返回0,接下来的1等等
>>Is this return UB ?
int someFunt ()
{
static int i = 0 ;

return i++ ;
}

WHat we want is the first time to return 0, next 1, etc




这很好,直到你达到INT_MAX。如果你不打算那么高,

没问题。



That''s fine, until you hit INT_MAX. If you don''t plan to get that high,
no problem.



谢谢理查德。

我认为在实际功能中有更多的逻辑用于环绕,

但问题的要点是关于返回的内容。


Joe


dada< jb ***** @ stny.rr.comwrote:
dada <jb*****@stny.rr.comwrote:

Richard Heathfield写道:
Richard Heathfield wrote:

dada说:
dada said:

>这是返回UB吗?

int someFunt ()

static int i = 0;


返回i ++;
}

我们想要的是第一次返回0,接下来的1等等
>Is this return UB ?

int someFunt ()
{
static int i = 0 ;

return i++ ;
}

WHat we want is the first time to return 0, next 1, etc



这没关系,直到你达到INT_MAX。如果你不打算那么高,

没问题。

That''s fine, until you hit INT_MAX. If you don''t plan to get that high,
no problem.



我认为实际函数中有更多逻辑用于回绕,

但问题的要点是关于返回的内容。


I think there is more logic in the actual function for wrap around,
but the gist of the question was about what was returned.



对不起,但实际上你并没有问一个问题(或者也许那里

但我的英语不是很好它)。如果问题是

函数在第一次调用时返回的那么答案是0.

第二次调用它时的返回值是1(帖子 -

fix ++ operator仅在expres-

sion的值被评估后应用。)

问候,Jens

-

\ Jens Thoms Toerring ___ jt@toerring.de

\ __________________________ http://toerring.de


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

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