小编rav*_*ard的帖子

For 循环不会在没有 return 语句的 int 函数中终止

在 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() 来解决的,但我很好奇为什么会发生这种情况。有任何想法吗?

c++ arduino undefined-behavior

2
推荐指数
1
解决办法
113
查看次数

为什么Makefile找不到包含目录

我似乎无法使用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运行测试软件。这或多或少是我的教程。

c++ gcc makefile

0
推荐指数
2
解决办法
196
查看次数

标签 统计

c++ ×2

arduino ×1

gcc ×1

makefile ×1

undefined-behavior ×1