本帖最後由 stephenwong 於 2021-7-2 10:53 編輯
用#define較可取
#define pin_light 7
void setup() {
pinMode(pin_light, OUTPUT);
...
}
vo ...
hon829 發表於 2021-7-1 18:54 
#define pin_light 7
同
const int pin_light = 7;
效果一樣,#define 呢,就係 preprocessor 時,以字換字。const int pin_light = 7; 呢,就係 compile stage 話俾個 compiler 知,有一常數,int 類型,數值係 7。Gen 出來啲 code 應該一樣嘅,無用多到 memory。但係,如果要 debug,#define <string> 會可能唔見咗,但係 const int 會見得返個 variable 名。好細分別嚟啫,可以不理! |