Arduino-Makefile icon indicating copy to clipboard operation
Arduino-Makefile copied to clipboard

Method Declarations before use

Open sm11963 opened this issue 12 years ago • 9 comments

Hello, I am wondering if I am missing something. I am using your Makefile and its working great. However, compiling fails unless I declare all of the functions used in the sketch before their use.

Am I missing some easy way around this? While this is just a minor annoyance, a way around this issue would certainly make it easier to use code that was previously written in the Arduino IDE.

sm11963 avatar Jun 10 '13 03:06 sm11963

Yes it is a known issue. May be I should add a note about it in the readme file.

The reason is that, the Arduino IDE, before compiling the files does a pre processing step where it automatically declares all methods. You can check out the code here https://github.com/arduino/Arduino/blob/master/app/src/processing/app/preproc/PdePreprocessor.java#L329

I was actually wondering whether we should do it as well or not. Check #39 and #49

The advantage is that, sketches which work in Arduino IDE will work without any change.

The counter argument is that, Arduino IDE does that, so that it is easy for beginners to start with. But makefiles are for people who know what is going on. Adding this feature will bloat it.

I actually see merit in both the arguments and have not decided which one to take. But I am open for suggestions as well.

sudar avatar Jun 10 '13 05:06 sudar

Are you talking about the "blah is undeclared in this scope" messages?

If we're trying to emulate the IDE i guess it should be fixed, but proper C++ requires you to declare your methods before calling them so.....

sej7278 avatar Jun 13 '13 13:06 sej7278

Are you talking about the "blah is undeclared in this scope" messages?

Yes.

If we're trying to emulate the IDE i guess it should be fixed, but proper C++ requires you to declare your methods before calling them so.....

As I said in the previous commit, I see merit in both the arguments.

I am not planning to implement it anytime soon. But if someone is interested in implementing it, then I would be happy to merge it :)

sudar avatar Jun 13 '13 15:06 sudar

Anyhow, does exists some CLI preprocessing utility which does the same (or similar) .ino->.cpp conversion, the way PdePreprocessor.java does? Or at least some ready to use script which takes all the functions declarations and put them into simple prototypes? I have some bigger project writen in arduino ide and I am looking for some easy way to switch from original IDE to vim, without big editing work on all my files. I thing this option would be good to address.

mkocer avatar Jul 29 '13 20:07 mkocer

Anyhow, does exists some CLI preprocessing utility which does the same (or similar) .ino->.cpp conversion, the way PdePreprocessor.java does? Or at least some ready to use script which takes all the functions declarations and put them into simple prototypes?

Unfortunately to the best of knowledge, the answer is no.

Since there wasn't much interest, we decided not to implement it.

But your usecase is a valid one. If I come to know of an implementation or if I end up implementing it, then I will let you know about it.

sudar avatar Jul 30 '13 05:07 sudar

shouldn't this be closed as its a wontfix ?

sej7278 avatar Feb 01 '14 01:02 sej7278

shouldn't this be closed as its a wontfix ?

I have marked this and #93 as wontfix, but didn't close it for two reasons

  • If it is closed, then someone else might create another ticket again for the same issue.
  • If someone is still interested in implementing it, then I am open to merge it.

Do you still feel that we should close it?

sudar avatar Feb 02 '14 14:02 sudar

no i see your point, i guess people wouldn't look through closed tickets for solutions.

sej7278 avatar Feb 02 '14 14:02 sej7278

I wrote a preprocessor, because I needed that feature for an App I'm working on. It could be used to create prototypes before using the Makefile. It's written in ruby and is inspired from here.

michaelbaisch avatar Mar 23 '15 20:03 michaelbaisch