在Windows中不同位置初始化变量给出了错误

Mar*_*k10 0 c c++ windows compiler-errors visual-studio-2012

我在我的代码中初始化简单的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'  

}
Run Code Online (Sandbox Code Playgroud)

我正在使用cl.exe编译器和visual studio 2012.I我正在从命令行编译代码

cl process.c 
Run Code Online (Sandbox Code Playgroud)

unw*_*ind 6

Visual Studio编译器不支持您尝试使用的C99.

您必须只使用C90,即将变量声明保留在其包含范围的顶部.