有趣的指针问题? [英] interesting pointer problem?
问题描述
我发现了一个有趣的指针问题。
指针是什么意思?
EXTERN short(* blocks)[64];
malloc是什么意思?
blocks =
(短(*)[64])malloc(count * sizeof(short [ 64]));
如有任何建议,将不胜感激!
祝你好运,
Davy
>
I found a interesting pointer problem.
What does the pointer mean?
EXTERN short (*blocks)[64];
And what does the malloc mean?
blocks =
(short (*)[64])malloc(count*sizeof(short [64]));
Any suggestions will be appreciated!
Best regards,
Davy
推荐答案
2005年9月6日星期二01:40:01 -0700,Davy写道:
On Tue, 06 Sep 2005 01:40:01 -0700, Davy wrote:
我找到了一个有趣的指针问题。
指针是什么意思?
EXTERN short(* blocks)[64];
EXTERN不是标准标识符,它可能被定义为一个宏
某处扩展到extern或什么都没有。
blocks是指向64个短裤数组的指针。
malloc是什么意思?
blocks =
(短(*)[64])malloc (count * sizeof(short [64]));
I found a interesting pointer problem.
What does the pointer mean?
EXTERN short (*blocks)[64];
EXTERN isn''t a standard identifier, it is probably defined as a macro
somewhere expanding to extern or nothing.
blocks is a pointer to an array of 64 shorts.
And what does the malloc mean?
blocks =
(short (*)[64])malloc(count*sizeof(short [64]));
这实际上分配了一个2D数组(实际上是数组数组)的数量
* 64个短路,其元素可以使用块[a] [b]访问。假设
当然,malloc()调用成功。
注意这是C和C ++有不同方法的情况。在C中你/ b
将倾向于在没有演员的情况下使用malloc()调用,在C ++中你会使用新的运算符来使用
。
>
劳伦斯
This allocates in effect a 2D array (in fact an array of arrays) of count
* 64 shorts whose elements can be accessed using blocks[a][b]. Assuming
the malloc() call succeeds of course.
Note this is a case where C and C++ have different approaches. In C you
would tend to use the malloc() call without the cast, in C++ you would
tend to use the new operator.
Lawrence
Davy写道:
Davy wrote:
我发现了一个有趣的指针问题。
>指针是什么意思?
EXTERN short(* blocks)[64];
假设EXTERN只是#defined与extern相同,这意味着声明了一个名为''blocks''的
变量(未定义)这是指向64个短值的
数组的指针。
malloc是什么意思?
blocks =
(短(*) [64])malloc(count * sizeof(short [64]));
I found a interesting pointer problem.
What does the pointer mean?
EXTERN short (*blocks)[64];
Assuming EXTERN is just #defined to be the same as extern, it means that a
variable named ''blocks'' is declared (not defined) that is a pointer to an
array of 64 short values.
And what does the malloc mean?
blocks =
(short (*)[64])malloc(count*sizeof(short [64]));
它分配''count''64个数组的短数并分配地址第一个
一个到''块''。
It allocates ''count'' arrays of 64 short and assigns the address of the first
one to ''blocks''.
谢谢你的帮助!
所以阻止是一个指向动态二维数组的指针,是吗?
我很困惑
"短(*块)[64];"
和短[64](*块);"
和short * blocks [64];" ;.
它们的区别是什么?
祝你好运,
Davy
Hi,
Thank you for your help!
So the "blocks" is a pointer to a dynamic 2-D array, is it?
I am confused with
" short (*blocks)[64];"
and " short [64] (*blocks);"
and "short *blocks [64];".
What''s their difference?
Best regards,
Davy
这篇关于有趣的指针问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!