How to test if a function is already defined in IAR ? (C)

Asked

Viewed 76 times

1

Hello,

I am making a library that should be easily portable to other programs. Soon, I tried to do the following:

01 #ifndef delay_ms
02 #define delay_ms(X)              OSTimeDlyHMSM(0u, 0u, 0u, (X), OS_OPT_TIME_HMSM_STRICT, &err)
03 #endif

However, set or not the function 'delay_ms()' the code at line 02 will be defined. There is a way to perform this test?

Grateful,

  • You want to define a macro that "covers" a missing function, but you want to leave the call to the native function if the function is available in the build environment?

  • The basic rule for macros is to write them in UPPERCASE. This avoids redefining previously declared functions ... #define DELAY_MS(x) OSTimeDlyHMSM(...)

  • @ctgPi exactly. Within my library I need a delay function. If it is set I use it, if not the library will use the Ostimedly function, which comes from the operating system used.

  • The right way to do it is to use autotools; the dirty way is to make a shell script that writes a mini-program #include <…> int main() { delay_ms(1000); } and tries to compile (no need to rotate) to see if there is an error (if given, inserts the definition in a .h which is dynamically built pre-compilation). I don’t know how to make the first approach and I don’t want to promote porqueira with the second; maybe someone with experience of autotools give you a strength.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.