【发布时间】:2014-09-23 11:11:37
【问题描述】:
我正在我的代码中初始化简单的 int 变量,但它会产生一些不需要的错误...如果我在某些地方使用整数(或其他数据类型)变量,它会产生错误。我写下我的代码并在整数变量显示错误的地方添加注释。
#include<stdio.h>
#include<Windows.h>
//int i; ///********* no problem ************
int main()
{
//int i; ///********* no problem ************
STARTUPINFO si;
PROCESS_INFORMATION pi;
//int i; ///********* no problem ************
ZeroMemory(&si,sizeof(si));
//int i; // error C2143: syntax error : missing ';' before 'type'
si.cb=sizeof(si);
//int i; //error C2143: syntax error : missing ';' before 'type'
ZeroMemory(&pi,sizeof(pi));
//int i; //error C2143: syntax error : missing ';' before 'type'
if(CreateProcess("C:\\Windows\\System32\\notepad.exe",NULL,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi))
{
//int i; ///********* no problem ************
printf("process created\n pid is=%d tid is=%d\n",pi.dwProcessId,pi.dwThreadId);
}
else
{
//int i; ///********* no problem ************
printf("process creation error\n");
}
// int i; // error C2143: syntax error : missing ';' before 'type'
}
我正在使用 cl.exe 编译器和 Visual Studio 2012。我正在从命令行编译代码
cl process.c
【问题讨论】:
-
一个重要提示,您不是在编译 C++ 程序,而是在编译 C 程序。
标签: c++ c windows visual-studio-2012 compiler-errors