C ++中函数参数的顺序 [英] Order of Function arguments in C++
问题描述
我在阅读" Bjarne Stroustrup的C ++样式和技术"常见问题解答,他提到了该常见问题解答 i ++ + i ++的价值是什么?
I was reading "Bjarne Stroustrup's C++ Style and Technique" FAQ where he mentioned about this FAQ What's the value of i++ + i++?
在此他提到了"...函数参数的求值顺序未定义."当他指的是f(v [i],i ++)时;例子.
In this he has mentioned "...the order of evaluation of function arguments are undefined." when he is refering to f(v[i],i++); example.
我知道函数参数的求值顺序不是未指定,但是在这种情况下是不确定的,因为我们依赖于i的值来确定v [i]的值.通过或者是FAQ本身的错误?
I am aware of that the order of evaluation of function arguments is unspecified not undefined but in this case is it undefined because we are relying on value of i so as to which v[i] to pass or its an error in the FAQ itself?
推荐答案
未指定函数参数的求值顺序,但表达式的行为未定义.比尼亚(Bjarne)错了. :-)
The order of evaluation of function arguments is unspecified but the behaviour of the expression is undefined. Bjarne has just got it wrong. :-)
查看此线程,以了解未指定行为"和未定义行为"之间的区别行为.
Check out this thread to understand the difference between Unspecified Behaviour and Undefined Behaviour.
我曾经问过Bjarne unspecified
和undefined
之间的区别,这是他的回答.
I once asked Bjarne the difference between unspecified
and undefined
and this was his reply..
就我个人而言,我不必理会未定义"与未定义"之间的区别.和未指定";你知道这是什么吗?在任何一种情况下,都应删除该代码并进行射击:(请小心避免使用"undefined"和"unspecified"一词)
Personally, I don't bother with the distinction between "undefined" and "unspecified"; do you know what it is? That code should be taken out and shot in either case: (carefully avoiding the words "undefined" and "unspecified")
.....
您不需要知道:只需避免两者.如果有人真的想知道他们可以在C ++或C标准中查找定义(我敢打赌,C和C ++标准将在不重要的细节上存在分歧).
You don't need to know: just avoid both. If someone really want to know they can look up the definitions in the C++ or C standards (my bet would be that the C and C++ standards will disagree on unimportant details).
这篇关于C ++中函数参数的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!