C语言struct的问题
Gcc下编译没有问题,但是到了vc2005,编译不过……
兄弟们帮我看看什么问题……
源代码如下:
#include "stdio.h"
struct testStruct
{
int aInt;
double aDouble;
};
typedef struct testStruct TestStruct;
typedef struct testStruct* pTestStruct;
main()
{
struct testStruct test;
test.aInt = 100;
test.aDouble = 10000.f;
printf("%d\n%f\n",test.aInt,test.aDouble);
pTestStruct structArray[100];
structArray[0] = (pTestStruct)malloc(sizeof(TestStruct));
structArray[0]->aInt = 100000;
structArray[0]->aDouble = 9998.2121f;
printf("%d\n%f\n",structArray[0]->aInt,structArray[0]->aDouble);
free(structArray[0]);
}
output窗口输出,怎么说pTestStruct使用不合法?
1>------ Build started: Project: CStruct, Configuration: Debug Win32 ------
1>Compiling...
1>test.c
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(20) : error C2275: 'pTestStruct' : illegal use of this type as an expression
1> f:\solutions - windowsprogramming\cstruct\cstruct\test.c(10) : see declaration of 'pTestStruct'
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(20) : error C2146: syntax error : missing ';' before identifier 'structArray'
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(20) : error C2065: 'structArray' : undeclared identifier
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(20) : error C2109: subscript requires array or pointer type
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(22) : error C2109: subscript requires array or pointer type
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(22) : warning C4013: 'malloc' undefined; assuming extern returning int
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(22) : warning C4312: 'type cast' : conversion from 'int' to 'pTestStruct' of greater size
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(23) : error C2109: subscript requires array or pointer type
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(24) : error C2109: subscript requires array or pointer type
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(27) : error C2109: subscript requires array or pointer type
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(27) : error C2109: subscript requires array or pointer type
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(28) : warning C4013: 'free' undefined; assuming extern returning int
1>f:\solutions - windowsprogramming\cstruct\cstruct\test.c(28) : error C2109: subscript requires array or pointer type
1>Build log was saved at "file://f:\Solutions - WindowsProgramming\CStruct\CStruct\Debug\BuildLog.htm"
1>CStruct - 10 error(s), 3 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========