Bug related to auto generation of function declarations

25 views
Skip to first unread message

Alexander Brevig

unread,
Sep 27, 2016, 4:36:33 PM9/27/16
to Arduino Developers
Hello everyone!

Here's and example that will break the auto generation of function declarations in the IDE, not sure for how long but I've gotten regular support request for a good while now.
The only thing I know, this used to work.

// say you have a library that accepts a callback
class BUG {public:BUG(void (*fn)(void)){}};

//void makeItBreak(){} //uncomment to fix
BUG b(makeItBreak); //this will break

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

Andrew Kroll

unread,
Sep 27, 2016, 5:30:03 PM9/27/16
to devel...@arduino.cc
Personally, I'm glad it breaks.
Auto declarations don't teach proper C++.
Yeah, I know, it is for people who are learning, so why not teach them the correct way :-)


--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@arduino.cc.



--
Visit my github for awesome Arduino code @ https://github.com/xxxajk

Jim Leonard

unread,
Sep 27, 2016, 5:58:27 PM9/27/16
to devel...@arduino.cc
Honestly I wish it would either work well or be gotten rid of completely.

The auto generation thing has been problematic for me in the past when I have functions that are passed structs/classes that I've defined as it will generate a declaration for me even when it's not needed and place the declaration above where I've defined my struct/class.

--jim
> > email to developers+...@arduino.cc.
> >
>
>
>
> --
> Visit my github for awesome Arduino code @ https://github.com/xxxajk
>
> --
> You received this message because you are subscribed to the Google Groups "Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.

Massimo Banzi

unread,
Sep 27, 2016, 6:01:05 PM9/27/16
to Arduino Developers
It works well in 90% of the cases or even better.

They only way to make it work 100% is to report bugs and provide a snippet of code.

I’m sure we can add an entry in the settings file that disables auto generation and let people do it by hand.

m

--
Massimo Banzi <m.b...@arduino.cc>
Arduino LLC

Andrew Kroll

unread,
Sep 27, 2016, 6:20:34 PM9/27/16
to devel...@arduino.cc
@Massimo: In that case, why not have these settings in a file with the project, so that someone does not need to set this for certain projects.

Personally, I have not had many problems.


>>> email to developers+unsubscribe@arduino.cc.

>>>
>>
>>
>>
>> --
>> Visit my github for awesome Arduino code @ https://github.com/xxxajk
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@arduino.cc.

>
> --
> You received this message because you are subscribed to the Google Groups "Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@arduino.cc.


--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@arduino.cc.

Cristian Maglie

unread,
Sep 28, 2016, 5:55:30 AM9/28/16
to devel...@arduino.cc
Il 28/09/2016 00:20, Andrew Kroll ha scritto:
> @Massimo: In that case, why not have these settings in a file with the
> project, so that someone does not need to set this for certain projects.
>
> Personally, I have not had many problems.


If you want to use pure C++ within the Arduino IDE, you can, what you
have to do is just create a new tab and name the file using the
extension .cpp. Those files are compiled as is and are not preprocessed.

BTW you must keep an empty .ino file with the same name of the sketch,
this is compulsory (you can leave it empty or add some comments for
documentation purposes).

C


--
Cristian Maglie <c.ma...@arduino.cc>

Cristian Maglie

unread,
Sep 28, 2016, 6:03:07 AM9/28/16
to devel...@arduino.cc

Alexander,

please open an issue here https://github.com/arduino/arduino-builder and
copy the exmample so it won't get lost.

C
> --
> You received this message because you are subscribed to the Google
> Groups "Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to developers+...@arduino.cc
> <mailto:developers+...@arduino.cc>.


--
Cristian Maglie <c.ma...@arduino.cc>

Cristian Maglie

unread,
Sep 28, 2016, 6:03:19 AM9/28/16
to devel...@arduino.cc
Il 27/09/2016 23:58, Jim Leonard ha scritto:
> Honestly I wish it would either work well or be gotten rid of completely.
>
> The auto generation thing has been problematic for me in the past when I have functions that are passed structs/classes that I've defined as it will generate a declaration for me even when it's not needed and place the declaration above where I've defined my struct/class.

Actually, the Arduino preprocessor handles 99.9% of the cases (the
millions of sketches build everyday with the Arduino IDE).

From time to time someone comes out with an example, of very convoluted
C++, that fails to compile because the Arduino preprocessor fails to
detect a prototype. This error is generally workaround by manually
declaring the "missed" prototype (as in this case).

More rarely someone comes out with an example where the failure of the
preprocessor cannot be worked-around.

I think that, if we try hard, we can always find a C++ example, complex
enough, that is not handled correctly by the preprocessor so, in a way,
the preprocessor will never be "perfect".

As I stated in my other post, if you really want to use all the advanced
features of C++ you can always create files with .cpp extensions that
are not preprocessed.

per1234

unread,
Sep 28, 2016, 6:32:34 AM9/28/16
to Developers
On Wednesday, September 28, 2016 at 3:03:07 AM UTC-7, Cristian Maglie wrote:

Alexander,

please open an issue here https://github.com/arduino/arduino-builder and
copy the exmample so it won't get lost.

I believe the issue has already been reported: https://github.com/arduino/arduino-builder/issues/50
The workaround(other than manually declaring the makeItBreak() prototype) is to change:


BUG b
(makeItBreak); //this will break

to:

BUG b
(&makeItBreak); //this will break
 

Alexander Brevig

unread,
Sep 28, 2016, 9:45:29 AM9/28/16
to Arduino Developers
My only problem with it is that I have several libraries which people actually seems to use, and they come to me for help - as it used to work for me and for them.

Keypad, Button, MenuBackend, TimedAction, FSM etc. They all defer some logic to a callback which I require at instantiation. The workarounds and all that is perfectly fine by me, I was just tired of the constant emails.


Though it's always nice to get in touch with the users even though I have to explain WProgram and the reason for this 'paradigm' suddenly failing.


I'll add it to the bug list. Thanks Christian

--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@arduino.cc.

Reply all
Reply to author
Forward
0 new messages