在 Arduino Uno 上,当在不返回任何内容的 int 函数中时,for 循环的行为非常奇怪。
void setup() {
Serial.begin(9600);
}
void loop() {
foo();
Serial.println("Never reached");
}
int foo() {
for (int i = 0; i < 9; i++) {
Serial.println(i);
}
}
Run Code Online (Sandbox Code Playgroud)
这将输出以下内容,并继续无限循环通过 ASCII ...
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
A
B
C
D
Run Code Online (Sandbox Code Playgroud)
此外,将 for 条件设为 i < 12 使其永远以数字方式计数,没有任何 ASCII 输出。
这都是通过添加return 0;到 foo() 来解决的,但我很好奇为什么会发生这种情况。有任何想法吗?
我似乎无法使用Makefile在测试程序中包含标头。
我试图尝试使用相对路径-I没有运气。我是Make的新手,由于某种原因,我很难理解它的用法。
我的代码, test.cpp
#include <iostream>
#include <results/enumTest.h>
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
和我的Makefile:
CFLAGS = -Wall -g -Wextra -Wpedantic -std=gnu++11 -m64 -Iinclude
test: test.o
gcc $(CFLAGS) -I/.. -o test test.o
test.o: test.cpp
gcc $(CFLAGS) -I/.. -c test.cpp
Run Code Online (Sandbox Code Playgroud)
我的目录结构:
/testDir/
./results/enuMtest.h
./test/test.cpp
./test/Makefile
Run Code Online (Sandbox Code Playgroud)
我希望我可以编译并使用Makefile运行测试软件。这或多或少是我的教程。