8

I have doubts about many things related with the different C specifications.

If I program a library in C99, can I use it from C89 code? (using only the functions with C89 compliant definitions).

example, this code would be usable in C89?

Header of a shared library:


#ifdef C99
 void func (double complex a, double complex b); // C99 function
#endif

 /* another C89 compliant function */
 void func2 (double a, double b);

Thanks in advance :)

castarco
  • 1,368
  • 2
  • 17
  • 33
  • Probably as long as you `#define C99` correctly. See http://stackoverflow.com/questions/2115867/is-there-a-define-for-c99 – BoltClock Dec 30 '10 at 16:31
  • @BoltClock I saw it :p , but my question is more oriented to the binary compatibility of C99 libraries with C89 programs. – castarco Dec 30 '10 at 16:34
  • @MK complex is a "new" type in C99 to work with complex numbers (with an "imaginary" component) – castarco Dec 30 '10 at 16:35

2 Answers2

8

The C language does not say anything about binary compatibility of C89 and C99 code. That is entirely up to the compilers you use for the different parts of the executable.

If you can make the external headers of your library palatable for a C89 compiler, I don't see any obvious reason why it would not work, except for the usual issue of making sure that two compilers can generate compatible code.

Bart van Ingen Schenau
  • 15,488
  • 4
  • 32
  • 41
2

Instead of #ifdef C99, use #if __STDC_VERSION__ > 199900L or similar.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711