Hi. I was trying to work with a library that is for both; arduino and maple..
If you want some code executed only in arduino:
#if defined(ARDUINO)
#else
#endif
is there something similar for maple too?
Hi. I was trying to work with a library that is for both; arduino and maple..
If you want some code executed only in arduino:
#if defined(ARDUINO)
#else
#endif
is there something similar for maple too?
If it is literally for "a library that is for both; arduino and maple"
#if !defined(ARDUINO)
...
#endif
would work, though it isn't very pleasing or very robust for a general case.
#if defined(_LIBMAPLE_H_)
...
#endif
might be better, if it is about libmaple.
But what is the test actually trying to restrict to, libmaple, a Maple vs Maple Mini, Cortex-M3?
I tried that, but in my example file-- I have tabbed 'em to keep it more clear.. Headers included by my example are included before libmaple.. So that won't work. Finally I sticked with #if defined(ARDUINO) arduino code #else maple code #endif
Can't restrict cortex-m3 or arm, as arduino got arm too(due).. This is in half duplex protocol library for serial/rs485..
jake1981 - "Headers included by my example are included before libmaple"
Why is it necessary?
It is not good practice. Try hard to avoid doing that.
There are several problems with including your own headers ahead of system headers:
1. Values defined accurately and correctly by system header files are no longer available. This tends to lead to: multiple declarations, which can introduce inconsistency, or using unnecessary equivalent but different declarations, which obscures codes purpose, or wired-in 'magic numbers' which can lead to less clear and more fragile code
2. Bugs in your header files can break system functions, making debugging harder, and increasing the amount of code which needs to be understood and tested.
3. The system-provided headers establish a coherent context, which helps an experienced developer read, use, debug and modify code. When the order of includes doesn't follow convention, that undermines the context that an experienced developer can use. Worse, that variation from common practice needs to be very clear, or the experienced developer will waste effort trying to understand why the common context does not support the application.
These problems reduce the value of using code.
I would recommend people to be very wary of varying from conventions without very strong, clearly documented, reasons.
Personally, I would not use code that fails to observe simple common practice without extremely strong reasons.
"Can't restrict cortex-m3 or arm, as arduino got arm too(due)"
The obvious solution is to use the _LIBMAPLE_H_ symbol, after fixing the header file sequence.
The other solution is define your own symbol in a small header file which documents the purpose of it, and takes care to ensure it is appropriately defined under the correct conditions. I would tend to refactor the MCU-unique parts in separate files too, and keep the code simple, with few pre-processor, #if defined()
directives.
Because my example doesn't include libmaple.h at all, it gets automaticly included by Maple IDE, but it propably is appended after other includes used, as when I tested this, it executed arduino code since _LIBMAPLE_H_ wasn't yet defined.
Instead of "_LIBMAPLE_H_", try "STM32_MEDIUM_DENSITY".
If your using the maple IDE to compile, then #ifdef MAPLE_IDE
works.
Not ideal, of course, and no idea if it'll be picked up if compiled outside the ide.
You must log in to post.