-1
我有以下代碼:更改預處理器變量到運行時因變量
#include <stdio.h>
#include <stdarg.h>
#define A 10
#define B 20
#define C 30
int m = A + B;
const int n = A + B + C;
void foo1(int x) {
m += A + B + x;
}
void foo2(int x = B, int y = C, ...) {
m += B + C + x;
if (m > n) foo1(y);
/* Some statements here */
}
/* And MUCH MORE functions and some global variables like these here. */
int main() {
/* Some statements here */
return 0;
}
我想這些A
,B
,C
作爲運行時因變量,這將在main()
功能處理(無#define
)。在不改變大部分代碼的情況下,將預處理器變量變爲運行時相關變量的最佳方法是什麼? (假設整個代碼超過1000行)。
您的默認參數符號無效C,但它是有效的在C++中。你學習哪種語言? –
最簡單的方法是用全局變量替換它們。雖然這可能不是一個好主意。 –
@JonathanLeffler好吧,我編輯了這個問題,因爲我不確定。順便說一句,我正在學習C. – arnobpl