Skip to main content
replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
Source Link

I can't reproduce your problem still. See this:

Compiler output


However if you are having problems (and frankly I expected you to) then you should read this:

How to avoid the quirks of the IDE sketch file pre-preprocessing

How the IDE organizes thingsHow the IDE organizes things


I can reproduce your problem in IDE 1.6.5 (not 1.6.7). The code generated by the IDE preprocessor is this:

#line 1 "sketch_jan11a.ino" #ifdef __cplusplus #include "Arduino.h" void start_timer(void); void setup(); void loop(); #line 2 extern "C" { #endif void start_timer(void); #ifdef __cplusplus } #endif void start_timer(void) { Serial.println("2"); Serial.begin(9600); delay(2000); } void setup() { start_timer(); Serial.println("4"); } void loop() { Serial.println("1"); delay(2000); } 

You can see that in the automatic function prototype generation that the IDE "helpfully" generates for you, it puts the prototype for start_timer outside the extern "C" declaration. Thus one function prototype has a declaration in C++ format, and the other in C format.

Why are you even doing this? I presume this is a small example of a larger problem.

If you follow the suggestions in my link How to avoid the quirks of the IDE sketch file pre-preprocessing - did you read that? - the problem goes away, because .cpp files in IDE tabs are not subjected to this extra processing.

I can't reproduce your problem still. See this:

Compiler output


However if you are having problems (and frankly I expected you to) then you should read this:

How to avoid the quirks of the IDE sketch file pre-preprocessing

How the IDE organizes things


I can reproduce your problem in IDE 1.6.5 (not 1.6.7). The code generated by the IDE preprocessor is this:

#line 1 "sketch_jan11a.ino" #ifdef __cplusplus #include "Arduino.h" void start_timer(void); void setup(); void loop(); #line 2 extern "C" { #endif void start_timer(void); #ifdef __cplusplus } #endif void start_timer(void) { Serial.println("2"); Serial.begin(9600); delay(2000); } void setup() { start_timer(); Serial.println("4"); } void loop() { Serial.println("1"); delay(2000); } 

You can see that in the automatic function prototype generation that the IDE "helpfully" generates for you, it puts the prototype for start_timer outside the extern "C" declaration. Thus one function prototype has a declaration in C++ format, and the other in C format.

Why are you even doing this? I presume this is a small example of a larger problem.

If you follow the suggestions in my link How to avoid the quirks of the IDE sketch file pre-preprocessing - did you read that? - the problem goes away, because .cpp files in IDE tabs are not subjected to this extra processing.

I can't reproduce your problem still. See this:

Compiler output


However if you are having problems (and frankly I expected you to) then you should read this:

How to avoid the quirks of the IDE sketch file pre-preprocessing

How the IDE organizes things


I can reproduce your problem in IDE 1.6.5 (not 1.6.7). The code generated by the IDE preprocessor is this:

#line 1 "sketch_jan11a.ino" #ifdef __cplusplus #include "Arduino.h" void start_timer(void); void setup(); void loop(); #line 2 extern "C" { #endif void start_timer(void); #ifdef __cplusplus } #endif void start_timer(void) { Serial.println("2"); Serial.begin(9600); delay(2000); } void setup() { start_timer(); Serial.println("4"); } void loop() { Serial.println("1"); delay(2000); } 

You can see that in the automatic function prototype generation that the IDE "helpfully" generates for you, it puts the prototype for start_timer outside the extern "C" declaration. Thus one function prototype has a declaration in C++ format, and the other in C format.

Why are you even doing this? I presume this is a small example of a larger problem.

If you follow the suggestions in my link How to avoid the quirks of the IDE sketch file pre-preprocessing - did you read that? - the problem goes away, because .cpp files in IDE tabs are not subjected to this extra processing.

Responded to comment.
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126

I can't reproduce your problem still. See this:

Compiler output


However if you are having problems (and frankly I expected you to) then you should read this:

How to avoid the quirks of the IDE sketch file pre-preprocessing

How the IDE organizes things


I can reproduce your problem in IDE 1.6.5 (not 1.6.7). The code generated by the IDE preprocessor is this:

#line 1 "sketch_jan11a.ino" #ifdef __cplusplus #include "Arduino.h" void start_timer(void); void setup(); void loop(); #line 2 extern "C" { #endif void start_timer(void); #ifdef __cplusplus } #endif void start_timer(void) { Serial.println("2"); Serial.begin(9600); delay(2000); } void setup() { start_timer(); Serial.println("4"); } void loop() { Serial.println("1"); delay(2000); } 

You can see that in the automatic function prototype generation that the IDE "helpfully" generates for you, it puts the prototype for start_timer outside the extern "C" declaration. Thus one function prototype has a declaration in C++ format, and the other in C format.

Why are you even doing this? I presume this is a small example of a larger problem.

If you follow the suggestions in my link How to avoid the quirks of the IDE sketch file pre-preprocessing - did you read that? - the problem goes away, because .cpp files in IDE tabs are not subjected to this extra processing.

I can't reproduce your problem still. See this:

Compiler output


However if you are having problems (and frankly I expected you to) then you should read this:

How to avoid the quirks of the IDE sketch file pre-preprocessing

How the IDE organizes things

I can't reproduce your problem still. See this:

Compiler output


However if you are having problems (and frankly I expected you to) then you should read this:

How to avoid the quirks of the IDE sketch file pre-preprocessing

How the IDE organizes things


I can reproduce your problem in IDE 1.6.5 (not 1.6.7). The code generated by the IDE preprocessor is this:

#line 1 "sketch_jan11a.ino" #ifdef __cplusplus #include "Arduino.h" void start_timer(void); void setup(); void loop(); #line 2 extern "C" { #endif void start_timer(void); #ifdef __cplusplus } #endif void start_timer(void) { Serial.println("2"); Serial.begin(9600); delay(2000); } void setup() { start_timer(); Serial.println("4"); } void loop() { Serial.println("1"); delay(2000); } 

You can see that in the automatic function prototype generation that the IDE "helpfully" generates for you, it puts the prototype for start_timer outside the extern "C" declaration. Thus one function prototype has a declaration in C++ format, and the other in C format.

Why are you even doing this? I presume this is a small example of a larger problem.

If you follow the suggestions in my link How to avoid the quirks of the IDE sketch file pre-preprocessing - did you read that? - the problem goes away, because .cpp files in IDE tabs are not subjected to this extra processing.

Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126

I can't reproduce your problem still. See this:

Compiler output


However if you are having problems (and frankly I expected you to) then you should read this:

How to avoid the quirks of the IDE sketch file pre-preprocessing

How the IDE organizes things