[英]How can I use an include guard for an Arduino library?
為什么在Example.h中將消息打印兩次? #pragma once
是否應該#pragma once
阻止它?
Example.h:
#pragma once
#pragma message "Included"
Example.cpp:
#include "Example.h"
Test.ino:
#include "Example.h"
void setup() {}
void loop() {}
輸出:
$ ~/Repositories/arduino-1.8.7/arduino --board arduino:avr:mega:cpu=atmega2560 --verify test/Test.ino`
Picked up JAVA_TOOL_OPTIONS:
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
In file included from /home/ToBeReplaced/Test/test/Test.ino:1:0:
/home/ToBeReplaced/Arduino/libraries/example/Example.h:2:17: note: #pragma message: Included
#pragma message "Included"
^
In file included from /home/ToBeReplaced/Arduino/libraries/example/Example.cpp:1:0:
/home/ToBeReplaced/Arduino/libraries/example/Example.h:2:17: note: #pragma message: Included
#pragma message "Included"
^
Sketch uses 656 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.
包含防護可防止將同一標頭多次包含在同一翻譯單元/代碼文件中。
兩個文件,每個文件都是分開編譯的,每個文件都包含帶有消息的標頭,每個文件在編譯時都會顯示該消息。
如果您再次將標頭和包含保護的標頭包含在同一個文件中,那么onyl仍然會對該文件顯示一次消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.