数组填充 [英] array padding
问题描述
您好,
索引数组的行为是否为负数(如[-1])
由标准定义?
Hello,
Is the behaviour of indexing an array with a negative number (like a[-1])
defined by the standard?
推荐答案
buda< ku ***** @ hotmail.com>写道:
buda <ku*****@hotmail.com> wrote:
你好,
索引数组的行为是否带有负数(如[-1])
由标准定义?
Hello,
Is the behaviour of indexing an array with a negative number (like a[-1])
defined by the standard?
不是101%肯定,但是[n]应该指向*(a +(sizeof(* a)* n)),所以它应该是
是* (a +(sizeof(a)* - 1)),即开始前的1个记忆点。
Not 101% certain, but a[n] should point to *(a+(sizeof(*a)*n)), so it should
be *(a+(sizeof(a)*-1)), that is 1 memory-spot before a starts.
" buda" <ク***** @ hotmail.com>写道:
"buda" <ku*****@hotmail.com> writes:
索引一个带有负数的数组的行为(如
a [-1])是否由标准定义?
Is the behaviour of indexing an array with a negative number (like
a[-1]) defined by the standard?
如果表达式引用现有的数组元素,则为。
否则,行为未定义。
例如,给出代码
int b [3];
int * a = b + 1;
表达式'a [-1]''有效并且引用与
`b [0]''相同的对象。
Martin
-
, - 。 Martin Dickopp,德国德累斯顿,=, - _-。 =。
/, - ) http://www.zero -based.org/ ((_ /)oo(\_))
\` - ''` - ''(。)` - ''
` - 。 Debian,GNU操作系统的一种变体。 \ _ /
If the expression refers to an existing array element, then yes.
Otherwise, the behavior is undefined.
For example, given the code
int b [3];
int *a = b + 1;
the expression `a [-1]'' is valid and refers to the same object as
`b [0]''.
Martin
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-'' `-''(. .)`-''
`-. Debian, a variant of the GNU operating system. \_/
buda写道:
你好,
索引数组的行为是否为负数(如[-1])
由标准定义?
Hello,
Is the behaviour of indexing an array with a negative number (like a[-1])
defined by the standard?
这是未定义的行为。见1999 C标准第6.5.6节。
Allin Cottrell
It''s undefined behaviour. See section 6.5.6 of the 1999 C standard.
Allin Cottrell
这篇关于数组填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!