Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It is possible to mix C89 code with C99 code?

Tags:

c

c99

c89

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 :)

like image 961
castarco Avatar asked Dec 30 '10 16:12

castarco


2 Answers

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.

like image 83
Bart van Ingen Schenau Avatar answered Nov 12 '22 12:11

Bart van Ingen Schenau


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

like image 35
R.. GitHub STOP HELPING ICE Avatar answered Nov 12 '22 13:11

R.. GitHub STOP HELPING ICE