0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

関数の出現順でエラーが起きるのを防ぐ

Last updated at Posted at 2021-07-30

ファイルの拡張子を.cppから.inoに変更するだけでビルドが通るようになります。

PlatformIOでArduinoの開発をしていて、技術ブログの記事にあるソースコード等を コピペ 参考にしたときなどに、
error: 'hoge' was not declared in this scope
のようなエラーがでることがあります。

例えば下のように、hoge()が使用されている場所より後ろで定義されている場合です。

void func1(){
  hoge();
}

void hoge(){
:
}

こんな時はhoge()が使用されるより前の場所に

void hoge();

とプロトタイプ宣言を入れるか、プロトタイプ宣言をまとめたヘッダーファイルを作成して#includeするか、またはhoge()をfunc1()の前に移動すればいいのですが、めんどくさいなー、今時そんな前時代的なことはしたくないなー、ってこともありますよね。
そんな時は、ファイルの拡張子を.cppから.inoに変更するだけでビルドが通るようになります。ただし
2021-07-30_103917.png

とのことなので注意が必要です。自分で試してみた限りではIntelliSenseちゃんと機能していましたが。。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?