# Function prototype with newline compiler error?

**URL:** <https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103>\
**Category:** IDE 2.x\
**Created:** [June 10, 2025, 9:49pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103 "2025-06-10T21:49:27Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikebeachbum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mikebeachbum/32/1129147_2.png) [@mikebeachbum](https://forum.arduino.cc/u/mikebeachbum)\
**Post date:** [June 10, 2025, 9:49pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/1 "2025-06-10T21:49:27Z")

</div>

Please forgive me if this is the incorrect place to post a newbie question and if you can, please direct me to the appropriate place if it is not.

I am new to Arduino but have been programming in C++ for many years. Perhaps too many years because I am getting a compiler error in Arduino that my Windows compiler doesn't have an issue with.  
This compiles fine in Arduino

```arduino
static bool afunc(void);
static bool afunc(void)
{
  return false;
}

```

But when I add a newline before afunc I get a compile error.

```arduino
static bool 
afunc(void);

static bool 
afunc(void)
{
  return false;
}

```

I believe that C++ is a free form language where spaces, tabs and newlines do not effect compilation. Does anyone know why I am getting a compile error? The error is strange too.

```arduino
x.ino:116:8: error: two or more data types in declaration of 'logTemperature' *<-- note that logTemperature is a function much lower down in the code.*

  116 | static bool

      | ^~~~

x:117:1: warning: ISO C++ forbids declaration of 'afunc' with no type [-fpermissive]

  117 | afunc(void)

      | ^ ~~~~

x:117:1: error: ambiguating new declaration of 'int afunc()'
x.ino:114:1: note: old declaration 'bool afunc()'

  114 | afunc(void);

      | ^ ~~~~

x.ino:114:1: warning: 'bool afunc()' declared 'static' but never defined [-Wunused-function]
x:114:1: warning: 'bool afunc()' used but never defined

```

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [June 10, 2025, 9:54pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/2 "2025-06-10T21:54:32Z")

</div>

Welcome to the forum

Please post the full error message

Which board are you compiling for ?

---

<div class="post-metadata">

**Author:** ![mikebeachbum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mikebeachbum/32/1129147_2.png) [@mikebeachbum](https://forum.arduino.cc/u/mikebeachbum)\
**Post date:** [June 10, 2025, 9:57pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/3 "2025-06-10T21:57:58Z")

</div>

Thank you so much for your reply! It is for the Teensy 4.1 board. I put the error message in the original message but here as well. Also, log Temperature is a function much further down in the code.

```arduino
x.ino:116:8: error: two or more data types in declaration of 'logTemperature'

  116 | static bool

      | ^~~~

x:117:1: warning: ISO C++ forbids declaration of 'afunc' with no type [-fpermissive]

  117 | afunc(void)

      | ^ ~~~~

x:117:1: error: ambiguating new declaration of 'int afunc()'

x.ino:114:1: note: old declaration 'bool afunc()'

  114 | afunc(void);

      | ^ ~~~~

x.ino:114:1: warning: 'bool afunc()' declared 'static' but never defined [-Wunused-function]

x:114:1: warning: 'bool afunc()' used but never defined

```

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [June 10, 2025, 10:05pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/4 "2025-06-10T22:05:13Z")

</div>

Also post ALL the code in code tags.

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [June 10, 2025, 10:12pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/5 "2025-06-10T22:12:20Z")

</div>

I put your code intyo my dummy test module and got oner clean compile and one not. The clean compile happens when I put this code as the last lines

```arduino
static bool 
afunc(void);

static bool 
afunc(void)
{
  return false;
}

```

but if I place those lines before the setup I get all kinds of weird errors.  
It does appear that the Arduino Language differs from C++ in this regard.

---

<div class="post-metadata">

**Author:** ![mikebeachbum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mikebeachbum/32/1129147_2.png) [@mikebeachbum](https://forum.arduino.cc/u/mikebeachbum)\
**Post date:** [June 10, 2025, 10:17pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/6 "2025-06-10T22:17:13Z")

</div>

Ah ok! Thanks! Yes my snippet is before setup. Thanks very much!

---

<div class="post-metadata">

**Author:** ![mikebeachbum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mikebeachbum/32/1129147_2.png) [@mikebeachbum](https://forum.arduino.cc/u/mikebeachbum)\
**Post date:** [June 10, 2025, 10:18pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/7 "2025-06-10T22:18:23Z")

</div>

Sorry but again very new here. What part of the code I posted wasn’t in code tags? Just trying to learn. Thanks

---

<div class="post-metadata">

**Author:** ![6v6gt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/6v6gt/32/225488_2.png) [@6v6gt](https://forum.arduino.cc/u/6v6gt)\
**Post date:** [June 10, 2025, 10:21pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/8 "2025-06-10T22:21:04Z")

</div>

I wonder if the 'split' version of the function definition is not recognised by the "special automatic function prototype generator feature" causing yet another prototype to be thrown in.  
I can't test it now but the preprocessor compiler output should show if this is the case.

---

<div class="post-metadata">

**Author:** ![oqibidipo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oqibidipo/32/221794_2.png) [@oqibidipo](https://forum.arduino.cc/u/oqibidipo)\
**Post date:** [June 10, 2025, 10:23pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/9 "2025-06-10T22:23:56Z")

</div>

The automatic prototype generation can get quite confused when things aren't on the same line.

Sketch:

```arduino
static bool
afunc(void);

static bool
afunc(void)
{
  return false;
}

void setup(){}
void loop(){}

```

After prototype generation:

```arduino
#include <Arduino.h>
#line 1 "/tmp/rjl/0611/forum_1388103/forum_1388103.ino"
static bool
afunc(void);

static bool
#line 10 "/tmp/rjl/0611/forum_1388103/forum_1388103.ino"
void setup();
#line 11 "/tmp/rjl/0611/forum_1388103/forum_1388103.ino"
void loop();
#line 5 "/tmp/rjl/0611/forum_1388103/forum_1388103.ino"
afunc(void)
{
  return false;
}

void setup(){}
void loop(){}

```

---

<div class="post-metadata">

**Author:** ![vedkhandelwal](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/vedkhandelwal/32/1128741_2.png) [@vedkhandelwal](https://forum.arduino.cc/u/vedkhandelwal)\
**Post date:** [June 10, 2025, 10:29pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/10 "2025-06-10T22:29:31Z")

</div>

Must be because _Arduino Cpp_ doesn't support double-line var initialization.  
Correct code:  
` static bool afunc(void);`  
Hope this article was helpful

---

<div class="post-metadata">

**Author:** ![6v6gt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/6v6gt/32/225488_2.png) [@6v6gt](https://forum.arduino.cc/u/6v6gt)\
**Post date:** [June 10, 2025, 10:32pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/11 "2025-06-10T22:32:30Z")

</div>

> [@oqibidipo](#):
>
> The automatic prototype generation can get quite confused when things aren't on the same line.

Indeed this is most likely but where did an `int` version of afunc() come from ?:

> [@mikebeachbum](#):
>
> `x:117:1: error: ambiguating new declaration of 'int afunc()'`

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [June 10, 2025, 10:33pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/12 "2025-06-10T22:33:16Z")

</div>

I think it was, my comment is just standard text.

---

<div class="post-metadata">

**Author:** ![oqibidipo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oqibidipo/32/221794_2.png) [@oqibidipo](https://forum.arduino.cc/u/oqibidipo)\
**Post date:** [June 10, 2025, 11:05pm UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/13 "2025-06-10T23:05:12Z")

</div>

> [@6v6gt](#):
>
> but where did an `int` version of afunc() come from ?:
> 
> > [@mikebeachbum](#):
> >
> > `x:117:1: error: ambiguating new declaration of 'int afunc()'`

```arduino
void loop();

afunc(void)
{
  return false;
}

```

This is one of the things that the 😡 😠 `-fpermissive` 😡 😠 option (which is on in the AVR core) enables: implicit function return type `int`.

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [June 11, 2025, 12:37am UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/14 "2025-06-11T00:37:43Z")

</div>

Hi @mikebeachbum. I have submitted a formal bug report to the Arduino developers on your behalf:

> <https://github.com/arduino/arduino-cli/issues/2931>
>
> \### Describe the problem
> 
> In order to make it easier for beginners to get starte…d with writing Arduino sketches, and for the convenience of all users, Arduino CLI \[automatically generates and adds prototypes for functions defined in a \`.ino\` file of a sketch\](https://arduino.github.io/arduino-cli/dev/sketch-build-process/#pre-processing).
> 
> Whitespace does not have syntactic significance to the C++ compiler, so users are free to format their code according to their preferences. This includes adding line breaks between any components of a function definition.
> 
> 🐛 Arduino CLI chooses an incorrect point to inject the generated function prototype under the following conditions:
> 
> \- The sketch contains a manual function prototype.
> \- The first function definition has a line break after the type.
> 
> This causes compilation to fail with a cryptic error.
> 
> \### To reproduce
> 
> \#### Setup environment
> 
> \`\`\`text
> $ arduino-cli version
> 
> arduino-cli Version: git-snapshot Commit: 2947cfb71 Date: 2025-06-10T23:45:14Z
> 
> $ mkdir -p "/tmp/FooSketch"
> 
> $ printf '
> void setup();
> void
> setup() {}
> void loop() {}
> ' \> "/tmp/FooSketch/FooSketch.ino"
> \`\`\`
> 
> \#### Demo
> 
> \`\`\`text
> $ arduino-cli compile --fqbn arduino:avr:uno "/tmp/FooSketch"
> 
> C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino:5:11: error: two or more data types in declaration of 'loop'
> void loop() {}
> ^
> C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino: In function 'int setup()':
> C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino:4:1: error: ambiguating new declaration of 'int setup()'
> setup() {}
> ^ ~~~~
> C:\\Users\\per\\AppData\\Local\\Temp\\FooSketch\\FooSketch.ino:2:6: note: old declaration 'void setup()'
> void setup();
> 
> \[...\]
> \`\`\`
> 
> 🐛 The compilation failed even though the sketch is valid C++.
> 
> By looking at the C++ code generated by the Arduino sketch preprocessor, we can see the cause of the error:
> 
> \`\`\`text
> $ arduino-cli compile --fqbn arduino:avr:uno --preprocess "/tmp/FooSketch"
> 
> \#include \<Arduino.h\>
> \#line 1 "C:\\\\Users\\\\per\\\\AppData\\\\Local\\\\Temp\\\\FooSketch\\\\FooSketch.ino"
> 
> void setup();
> void
> \#line 5 "C:\\\\Users\\\\per\\\\AppData\\\\Local\\\\Temp\\\\FooSketch\\\\FooSketch.ino"
> void loop();
> \#line 4 "C:\\\\Users\\\\per\\\\AppData\\\\Local\\\\Temp\\\\FooSketch\\\\FooSketch.ino"
> setup() {}
> void loop() {}
> \`\`\`
> 
> 🐛 The compilation failure was caused by Arduino CLI injecting the function prototype for \`void loop()\` inside the definition of the \`void setup()\` function.
> 
> 
> \### Expected behavior
> 
> Generated function prototypes are not injected inside function definitions.
> 
> \### Arduino CLI version
> 
> 2947cfb71
> 
> \### Operating system
> 
> N/A, Windows
> 
> \### Operating system version
> 
> 11
> 
> \### Additional context
> 
> Originally reported at https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103
> 
> \<a name="workaround"\>\</a\>
> 
> \#### Workaround
> 
> Refrain from adding a line break after the type in function definitions.
> 
> \#### Related
> 
> \- https://github.com/arduino/arduino-cli/issues/1944
> \- https://github.com/arduino/arduino-cli/issues/1253
> \- https://github.com/arduino/arduino-cli/issues/2696
> \- https://github.com/arduino/arduino-cli/issues/1800
> \- https://github.com/arduino/arduino-cli/issues/1591
> \- https://github.com/arduino/arduino-cli/issues/1618
> \- https://github.com/arduino/arduino-cli/issues/1785
> \- https://github.com/arduino/arduino-cli/issues/2161
> \- https://github.com/arduino/arduino-cli/issues/2697
> 
> 
> \### Issue checklist
> 
> \- \[x\] I searched for previous reports in \[the issue tracker\](https://github.com/arduino/arduino-cli/issues?q=)
> \- \[x\] I verified the problem still occurs when using the \[nightly build\](https://arduino.github.io/arduino-cli/dev/installation/#nightly-builds)
> \- \[x\] My report contains all necessary details

Until such time as the bug might be fixed, the workaround will be to refrain from adding a line break after the type in your function definitions.

---

<div class="post-metadata">

**Author:** ![mikebeachbum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mikebeachbum/32/1129147_2.png) [@mikebeachbum](https://forum.arduino.cc/u/mikebeachbum)\
**Post date:** [June 11, 2025, 12:42am UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/15 "2025-06-11T00:42:23Z")

</div>

Thank you very much for your and everyone’s help with this. This is a great development community that I am very happy to being a part of.

---

<div class="post-metadata">

**Author:** ![6v6gt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/6v6gt/32/225488_2.png) [@6v6gt](https://forum.arduino.cc/u/6v6gt)\
**Post date:** [June 11, 2025, 6:42am UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/16 "2025-06-11T06:42:44Z")

</div>

> [@oqibidipo](#):
>
> This is one of the things that the 😡 😠 `-fpermissive` 😡 😠 option (which is on in the AVR core) enables: implicit function return type `int`.

Generating unwanted function return types is almost as bad as generating unwanted function prototypes 😀

Incidentally, this behaviour of automatic function generation was already present in the "Processing" development system on which the Arduino "language" was based. That is, according to deepseek AI.

> [@](#):
>
> Yes, the **Processing** language (on which the Arduino IDE is based) also **automatically generates function prototypes** for user-defined functions, similar to the Arduino IDE. This behavior is inherited from their shared history, as both Processing and the Arduino IDE were designed to simplify coding for beginners by handling some of the more manual aspects of C/C++ compilation.

So the Arduino IDE developers are not necessary to blame for the consequences of all this and need not be too defensive about it IMHO.

---

<div class="post-metadata">

**Author:** ![ptillisch](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@ptillisch](https://forum.arduino.cc/u/ptillisch)\
**Post date:** [June 11, 2025, 7:23am UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/17 "2025-06-11T07:23:34Z")

</div>

> [@6v6gt](#):
>
> Generating unwanted function return types is almost as bad as generating unwanted function prototypes

The problems caused by the inclusion of the `-fpermissive` flag in the compilation command templates, and the proposal for removal of the flag are tracked by the Arduino developers here:

> <https://github.com/arduino/Arduino/issues/10154>
>
> Hi.
> There is the problem.
> 
> =====================================================…========
> 
> \`\`\`
> void setup() {
> Serial.begin(9600);
> Serial.println("Start");
> }
> 
> void loop() {
> char ch = Serial.read();
> switch(ch){
> case '1':
> Serial.println("Block 1 starts executing");
> // Some block 1
> break;
> case '2':
> Serial.println("Block 2 starts executing");
> byte b;
> b = 0; // It's OK.
> // Some block 2
> break;
> case '3':
> Serial.println("Block 3 starts executing");
> // Some block 3
> break;
> case '4':
> Serial.println("Block 4 starts executing");
> // Some block 4
> break;
> }
> }
> \`\`\`
> Sketch uses 1668 bytes (5%) of program storage space…
> Global variables use 294 bytes (14%) of dynamic memory…
> 
> =============================================================
> 
> \`\`\`
> void setup() {
> Serial.begin(9600);
> Serial.println("Start");
> }
> 
> void loop() {
> char ch = Serial.read();
> switch(ch){
> case '1':
> Serial.println("Block 1 starts executing");
> // Some block 1
> break;
> case '2':
> Serial.println("Block 2 starts executing");
> byte b = 0; // This causes the problem! All blocks below the 2nd are never executed !!!
> // However, the value of the local variable in the 2nd block remains correct!
> // Some block 2
> break;
> case '3':
> Serial.println("Block 3 starts executing");
> // Some block 3
> break;
> case '4':
> Serial.println("Block 4 starts executing");
> // Some block 4
> break;
> }
> }
> \`\`\`
> Sketch uses 1596 bytes (4%) of program storage space…
> Global variables use 244 bytes (11%) of dynamic memory…
> 
> =============================================================
> 
> Note the noticeably smaller code size in the second case.
> Moreover, this does not depend on the number of blocks below the second one!
> It looks like the linker just doesn't include them in the final code!
> 
> \### Additional context
> 
> \#### Additional reports
> 
> \- https://github.com/arduino/Arduino/issues/11402
> \- https://github.com/arduino/Arduino/issues/11639

> <https://github.com/arduino/ArduinoCore-avr/issues/268>
>
> Today, I ran into some problem, which turned out to be caused by the compiler ha…ppily passing an \`int\` to a function that expected a pointer. Closer investigation showed that a warning was issued, where I would have expected an error. This seems to because of the \`-fpermissive\` flag, which gets passed by the avr core by default. According to the gcc manpage:
> 
> \`\`\`
> -fpermissive
> Downgrade some diagnostics about nonconformant code from
> errors to warnings. Thus, using -fpermissive allows some
> nonconforming code to compile.
> \`\`\`
> 
> I'm not sure what changes this makes exactly and if we need it at all. If the other changes are similar to this one, I think it should be disabled at some point (but it will probably break existing code that isn't quite correct, but now happens to work)...
> 
> For reference, here's a simplified version of my problem:
> 
> \`\`\`
> void func(Foo \*ptr);
> 
> int main() {
> func(1);
> return 0;
> }
> \`\`\`
> 
> (the real problem was more subtle, involving a struct with a conversion operator to int, which got silently converted to a pointer containing rubbish when I forgot the \`&\` operator when trying to pass the struct's address to a function).
> 
> \### Additional context
> 
> \#### Additional requests
> 
> \- https://github.com/arduino/ArduinoCore-avr/issues/268#issuecomment-254016077
> \- https://github.com/arduino/Arduino/issues/10154
> \- https://github.com/arduino/Arduino/issues/10154#issuecomment-643845516
> \- https://github.com/arduino/Arduino/issues/11402
> \- https://github.com/arduino/Arduino/issues/11639
> 
> \#### Related
> 
> \- https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/13

> [@6v6gt](#):
>
> this behaviour of automatic function generation was already present in the "Processing" development system

The programming language used by [**Processing**](https://processing.org/) is essentially Java (I think they actually do the same as Arduino and consider it to be a new language). I don't know anything about Java, but my understanding is that, unlike C++, function prototypes (AKA "forward declarations") are not used in Java.

It might well be that prototype generation was already in place in the [**Wiring**](https://www.wiring.org.co/) IDE at the time Arduino forked it though.

---

<div class="post-metadata">

**Author:** ![6v6gt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/6v6gt/32/225488_2.png) [@6v6gt](https://forum.arduino.cc/u/6v6gt)\
**Post date:** [June 11, 2025, 7:58am UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/18 "2025-06-11T07:58:33Z")

</div>

I'd forgotten about the "Wiring" phase in the evolution of Arduino. That was all before my time 🙂 . The lesson anyway is that well meaning efforts, such as those referenced here, to make life simpler for new users have to be very carefully thought through to avoid creating bigger problems in the future.

Interesting is that the small sketch produced by the OP managed simultaneously to demonstrate two of these controversial issues.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 8, 2025, 7:59am UTC](https://forum.arduino.cc/t/function-prototype-with-newline-compiler-error/1388103/19 "2025-12-08T07:59:10Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
