20070904 vc c1001 二维数组
http://www.yippeesoft.com
将LINUX共享目录映射盘符,VC编译发现C1001错误
解决办法,去掉预编译头文件
VC6.0的一个编译错误的解决
在window98下使用vc6.0时,如果预编译头文件(stdafx.h)中包含了模板类的头文件,比如atl的头文件时,编译器会报错:
fatal error C1001: INTERNAL COMPILER ERROR
(compiler file \’msc1.cpp\’, line 1786)
造成这种问题的原因是编译器分配的内存超过了限制。
解决的办法有三种:
1.给编译器增大内存限制。在project(工程)->setting(设置)->c/c++的project option(工程选项)中,添加/Zm#nn选项,#nn是一个数字,取值最大为2000。默认为100。但是这种方法好像没有什么用处。
2.将模板类头文件从stdafx.h中移出;
3.不使用预编译头文件。project->setting->c/c++,选择所有的.cpp文件,都使用“不使用预编译头文件“的选项。缺点是编译的时候很慢
?
fatal error C1001
When template classes or template class header files are included in a precompiled header file, the compiler may generate the following error for files that use the precompiled header
This error occurs only on machines with the Windows 95 or Windows 98 operating system.
RESOLUTION
Use one of the following three suggested workarounds:
Use compiler switch /Zm#nn to increase the compiler\’s heap memory allocation limit. The default value of #nn is 100 and the maximum value is 2000. Manually add this switch in Developer Studio: under the Project menu, click Setting, the click C/C++, then Project Options. Usually, a value of 1000 works.
NOTE: You may need to increase the system virtual memory to accommodate the increased #nn for /Zm. 工程&line; 设置 &line; “C/C++” &line; “工程选项"
-or-
Remove the template class header files from the precompiled header file.
-or-
Use "Automatic use of precompiled headers" (/YX switch), or, "Not using precompiled header."
This error is most often generated in one of two cases:
Failure to recover the compiler\’s internal state following detection of a syntax error in the program. The first pass of the compiler will occasionally fail when attempting to recover its state following the detection of a malformed program. Typically, the compiler will have printed an error message (or messages) and will later produce an internal compiler error. In most cases, fixing the errors reported in your code and recompiling will solve the problem.
Failure of the code generator to find a way to generate correct code for a construct. This is most often caused by the interaction of an expression and an optimization option. The optimization has generated a tree which the compiler does not know how to handle. Such a problem can often be fixed by removing one or more optimization options when compiling the particular function containing the line indicated in the error message.
If no error messages have been emitted prior to the internal compiler error, then the next step is to determine which pass of the compiler is emitting the internal compiler error. This can be determined by recompiling the application with the /Bd option included. The /Bd option will cause each pass to print its name and arguments when it is invoked. The last pass invoked before the error is emitted is the one responsible.
If the pass indicated is P1, then the likely problem is still error recovery, as in number one above, but it is happening before the compiler has had a chance to emit the error message for the error it has just discovered. In such a case, examine the line on which the internal compiler error is reported. This line may also contain an unreported syntax error. Fixing any errors you find on that line will solve the internal compiler error in most cases. If you cannot find any error on that line or on the line previous to the one reported, contact Microsoft Product Support Services for help.
If the pass indicated is P2, then the problem can usually be fixed by removing one or more optimization options (or using a different code generator). You can determine which option is at fault by removing them one at a time and recompiling until the message goes away. Generally the last one removed is the problem and all other optimizations can be used safely. The most common culprits are /Og, /Oi, and /Oa. Once the offending optimization is discovered, it need not be turned off for the entire compilation. The offending optimization can be disabled with the optimize pragma while compiling the function where the error occurred, but enabled for the rest of the module.
More rarely, such errors occur at very low optimization levels or even when optimization is disabled. In such cases, rewriting the line where the error is reported (or possibly several lines including the one causing the error) may be a solution. If none of these options works, consult the technical support help file or the technical support section in one of your manuals.
二维数组的初始化和参数传递
以char型的二维数组为例,它的初始化分为以下几种:
char str[][3] = …&leftsign;"a","cd","ef"&rightsign;;
void Printf(char str[][3], int count)
…&leftsign;
for(int i= 0; i < count; i++)
…&leftsign;
printf("%s", str[i]);
printf(" ");
&rightsign;
&rightsign;
这种情况下,数组只声明列数,没有声明行数;实际行数由初始化时确定;初始化时,根据例中所示,每个字符串最多有2个字符,另一个是\’\\0\’;传参数的时候,由于不知道行数,故需要额外的参数传递行数。sizeof(str)为9。
char* str[3] = …&leftsign;"ab","cdf","high"&rightsign;;
void Printf(char* str[3])
…&leftsign;
for(int i= 0; i < 3; i++)
…&leftsign;
printf("%s", str[i]);
printf(" ");
&rightsign;
&rightsign;
这种情况下,实际声明的是一个指向字符串数组的指针,数组有3个元素;由于数组元素个数编译时已经知道,故不需要额外传递个数。sizeof(str)为4X3 = 12。
char str[4][3] = …&leftsign;"d","df","hi", "g"&rightsign;;
void Printf(char (*str)[3], int count)
…&leftsign;
for(int i = 0; i < count; i++)
…&leftsign;
printf("%s", str[i]);
printf(" ");
&rightsign;
&rightsign;
大多数int等其他类型的二维数组都如这种方式声明,需要传递行数。
历史博文
- 20081006 c# ip address change - 2009
- 1231 多普达818 短信 摄像头驱动 - 2007
- 0220 Eclipse cdt mingw info - 2006
- Windows下的CVS版本控制软件使用-CVS客户端WINCVS/TortoiseCVS - 2005