关于指针 Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiBase/html/delphi_20061206091612270.html
在C++中:
int *p;
请问p[1]在delpi中怎么表示.
C++里的int * p ;是定义了一个整型指针
在delphi里就是 var p:^integer;
p[1]-----有意义吗?我不知道.
我现在有一段VC++的代码,里面就有这样的用法。
如果说下标是0,还可以理解为&p == &p[0]
但是p[1],已经越界了
那请你看一下这段段码怎么园为Delphi代码:
static void idctrow(short *blk)
{
int x0, x1, x2, x3, x4, x5, x6, x7, x8;
/* shortcut */
if (!((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) |
(x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3])))
{
blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3;
return;
}
x0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage */
/* first stage */
x8 = W7*(x4+x5);
x4 = x8 + (W1-W7)*x4;
x5 = x8 - (W1+W7)*x5;
x8 = W3*(x6+x7);
x6 = x8 - (W3-W5)*x6;
x7 = x8 - (W3+W5)*x7;
/* second stage */
x8 = x0 + x1;
x0 -= x1;
x1 = W6*(x3+x2);
x2 = x1 - (W2+W6)*x2;
x3 = x1 + (W2-W6)*x3;
x1 = x4 + x6;
x4 -= x6;
x6 = x5 + x7;
x5 -= x7;
/* third stage */
x7 = x8 + x3;
x8 -= x3;
x3 = x0 + x2;
x0 -= x2;
x2 = (181*(x4+x5)+128)>>8;
x4 = (181*(x4-x5)+128)>>8;
/* fourth stage */
blk[0] = (x7+x1)>>8;
blk[1] = (x3+x2)>>8;
blk[2] = (x0+x4)>>8;
blk[3] = (x8+x6)>>8;
blk[4] = (x8-x6)>>8;
blk[5] = (x0-x4)>>8;
blk[6] = (x3-x2)>>8;
blk[7] = (x7-x1)>>8;
}
我不懂这些位移是怎么回事,有点晕了....帮你顶....
要看p指向的内存了,在C中,指针和数组有很大的相似性
如p=(int *)malloc(10 * sizeof(int)); p指向一个数组
c也不检查数组越界,内存访问逻辑是否正确,全凭自己