![]() |
#2
flyingcloude2010-07-10 10:20
|

// test.cpp
#include "test.h"
const char test[] = "This is a test file\n";
// test.h
extern const char test[];
// main.cpp
#include <stdio.h>
#include "test.h"
int main(int argc, char **argv)
{
printf("%s, %d\n", test, sizeof(test));
return 0;
}
为什么这样的程序会出现语法错误?提示 sizeof(test)操作非法呢?#include "test.h"
const char test[] = "This is a test file\n";
// test.h
extern const char test[];
// main.cpp
#include <stdio.h>
#include "test.h"
int main(int argc, char **argv)
{
printf("%s, %d\n", test, sizeof(test));
return 0;
}
VC具体编译错误信息:
d:\program_files\microsoft visual studio\myprojects\test\bcd.cpp(41) : error C2070: illegal sizeof operand
[ 本帖最后由 vfdff 于 2010-7-10 20:14 编辑 ]