[英]Code doesn't compile: error C2099: initializer is not a constant
我正在嘗試使用最初用C編寫的軟件在Visual C ++中編譯。 這是我到目前為止的代碼:
#include "timer.h"
FILE * timerFP = stdout;
int timerCount = 0;
double time_Master = 0.0;
static tsc_type tsc_Master;
void Timer_Start(void)
{
readTSC(tsc_Master);
}
void Timer_Stop(void)
{
tsc_type tsc_Master2;
readTSC(tsc_Master2);
time_Master += diffTSC(tsc_Master,tsc_Master2);
}
但Visual C ++給我以下錯誤:
error C2099: initializer is not a constant.
我該如何解決? 謝謝。
正如評論者已經指出的那樣, stdout
不需要是常數。 例如,在MSVC ++ 2013中,它在%PROGRAMFILES(x86)%\\Microsoft Visual Studio 12.0\\VC\\include\\stdio.h
第150行上定義如下:
#define stdout (&__iob_func()[1])
這意味着它涉及函數調用。 初始化器需要是編譯時常量, stdout
不是。
(請注意,這在不同版本的MSVC ++之間會發生變化,因此您的版本可能會有所不同)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.