|
我正在搭建全新的HugeCalc架构,尝试采用mathe曾给出的建议。
但编译时遇到一条提示 error C2016: C requires that a struct or union has at least one member
为了分析问题,我写了个简单的测试程序:- typedef struct _HI{} *PHI;int main(void){ int i; PHI p; p = (PHI)&i; return 0;}
复制代码 如果存成 test.cpp,在 VC2008 及 VC6 下均顺利编译通过。
但若修改文件名为 test.c,在VC6 下提示:Deleting intermediate files and output files for project 'test - Win32 Debug'.
--------------------Configuration: test - Win32 Debug--------------------
Compiling...
test.c
e:\jason\test\test.c(1) : error C2059: syntax error : '}'
e:\jason\test\test.c(6) : error C2065: 'PHI' : undeclared identifier
e:\jason\test\test.c(6) : error C2146: syntax error : missing ';' before identifier 'p'
e:\jason\test\test.c(6) : error C2065: 'p' : undeclared identifier
Error executing cl.exe.
test.exe - 4 error(s), 0 warning(s)
在VC2008下提示:------ Rebuild All started: Project: test, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'test', configuration 'Debug|Win32'
Compiling...
test.c
e:\jason\test\test.c(1) : error C2016: C requires that a struct or union has at least one member
Build log was saved at "file://e:\Jason\test\Debug\BuildLog.htm"
test - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
我想问的是:为什么C中不允许定义空的结构体?而C++既然允许,是什么原因呢? |
|