Search code examples
cfunctioncallc-preprocessor

#Define Entire function call with arguments?


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?


Solution

  • 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.