Reputation: 169
I have a program that I am running on two different compilers, and each compiler has a different file handling library. For example on library requires:
fwrite(buffer,size,elements,file)
While the other is:
f_write(file,buffer,size,elements)
is there anyway I could use a global #define
in my main header file inside of a #ifdef
statement that would allow me to seamlessly transition between compilers?
Upvotes: 2
Views: 181
Reputation:
Sure:
#ifdef STUPID_COMPILER
# define fwrite(ptr, size, nitems, stream) f_write(stream, ptr, size, nitems)
#endif
Then just use fwrite()
in your code -- no wrapper function needed. The preprocessor will translate it to an f_write()
call if you're using the compiler/library that requires that.
Upvotes: 7
Reputation: 182619
You could make a new function:
size_t my_fwrite(...)
{
#ifdef REAL_FWRITE
return fwrite(buffer,size,elements,file);
#elif F_WRITE
return f_write(file,buffer,size,elements);
#else
#error "No fwrite"
#endif
}
What kind of implementation doesn't provide fwrite
but has f_write
?
Upvotes: 2