- #1
- 978
- 693
I am trying to port an Arduino C library onto a NodeMCU using the Arduino IDE. (Edit: actually I am porting a sketch that uses the library, from Arduino to NodeMCU)
There are some functions (members of a certain class) that take enum arguments, but I need to provide int values because the values come in over serial or WiFi. On the Arduino I can just feed ints to the original function and it converts them nicely into the required enums. But when compiling for NodeMCU it raises an error like "can't convert int to enum, -fpermissive".
I am now overloading the function with an additional prototype line in the ".h" file and a modified function definition in the library's ".c" file.
My questions:-
(a) why doesn't it work if I put the new prototype line in my main code just after the library's include line? Why do I have to put it in the library's ".h" file? My understanding was that the compiler just merges all the included contents into the main file before processing. In that case it shouldn't matter if my prototype line followed the include line in my code, or was inside the header file.
(b) Is there some other simple way of overloading the function by writing stuff in my file rather than touching the supplied libraries, keeping in mind that the function is part of a class?
There are some functions (members of a certain class) that take enum arguments, but I need to provide int values because the values come in over serial or WiFi. On the Arduino I can just feed ints to the original function and it converts them nicely into the required enums. But when compiling for NodeMCU it raises an error like "can't convert int to enum, -fpermissive".
I am now overloading the function with an additional prototype line in the ".h" file and a modified function definition in the library's ".c" file.
My questions:-
(a) why doesn't it work if I put the new prototype line in my main code just after the library's include line? Why do I have to put it in the library's ".h" file? My understanding was that the compiler just merges all the included contents into the main file before processing. In that case it shouldn't matter if my prototype line followed the include line in my code, or was inside the header file.
(b) Is there some other simple way of overloading the function by writing stuff in my file rather than touching the supplied libraries, keeping in mind that the function is part of a class?