使用类型定义的...without。
我的老板声称,有一次他在面试中被问到这个问题,当他给出答案时,面试官告诉他不能使用typedefs,因为这是糟糕的风格。
无论如何,他喜欢把这个问题抛给人们,看看他们是否能做对,通常是在新程序员的午餐上。没有人会做对(尤其是手头没有笔、纸或电脑)。我想准备好下次他试图用它来对付某人>:D
发布于 2009-07-16 08:25:26
void* array[m][n];会给你一个空指针的二维数组。我不知道这有什么令人困惑的,除非我误解了你的问题。
发布于 2009-07-16 15:24:11
指向什么的2D指针数组?
T *p[N][M]; // N-element array of M-element array of pointer to T
T (*p[N][M])(); // N-element array of M-element array of pointer to
// function returning T如果我们讨论的是指向二维数组的指针,那么事情只会变得更有趣一些:
T a[N][M]; // N-element array of M-element array of T
T (*p)[M] = a; // Pointer to M-element array of T
T (**p2)[M] = &p; // Pointer to pointer to M-element array of T
T (*p3)[N][M] = &a; // Pointer to N-element array of M-element
// array of T
T (**p4)[N][M] = &p3; // Pointer to pointer to N-element array of
// M-element array of T编辑:等等,我想我可能找到你想要的东西了。
T *(*a[N])[M]; // a is an N-element array of pointer to M-element
// array of pointer to T编辑:现在我们变得很傻了:
T *(*(*a)[N])[M]; // a is a pointer to an N-element array of
// pointer to M-element array of pointer to T
T *(*(*(*f)())[N])[M]; // f is a pointer to a function returning
// a pointer to an N-element array of pointer
// to M-element array of pointer to T
T *(*(*f[N])())[M]; // f is an N-element array of pointer to
// function returning pointer to M-element
// array of pointer to T对于那些精神错乱的人:
T *(*(*(*(*(*f)())[N])())[M])(); // f is a pointer to a function
// returning a pointer to a N-element
// array of pointer to function
// returning M-element array of
// pointer to function returning
// pointer to TTypedefs是为wusse准备的。
发布于 2009-07-16 08:24:35
void*** p2DArray = (void***)malloc( numAxis1 * sizeof( void** ) );
int count = 0;
while( count < numAxis1 )
{
p2DArray[count] = (void**)malloc( numAxis2 * sizeof( void* ) );
count++;
}这就对了。现在,您可以通过p2DArrayn访问数组,并获取存储在那里的空*。
不管怎样,我不明白为什么你需要使用typedefs ...
编辑:哈哈哈哈或avakar建议;)
https://stackoverflow.com/questions/1136146
复制相似问题