Is this possible in C to import a library function under a different name?
like say ideally this fake C syntax:
char *malloc(int) as mymalloc;
instead of malloc
as it is known in the library file it becomes mymalloc
. And and identifier malloc
is not declared, and is available for future declarations.
I need this for some specific use case when the third party large header file can be optionally included later, but few functions must be always used. So I need another micro header that defines those same few functions as the bigger header declares(or not) later. This all is a part of a progamming language that compiles to C, so the weird requirement is that small header must define functions before the large header file. Also I cannot use some trivial ifdef
solutions because large header does not know about me and I cannot modify it. The functions in question take a complex structure pointer as parameter, but I just declare them as talking void*
thus compiler will bark at "incompatible redefinition".
CLUMSY_STRUCTURE *create_struct();
do_something(CLUMSY_STRUCTURE *);
and the definition of CLUMSY_STRUCTUREs is pages long, and I do not want them in my tiny header.
Also I am not sure even if I redefine CLUMSY_STRUCTURE will the compiler think two declarations are compatible, when it sees the second declaration.