Undefine a library function

Niklaus niklaus@gmail.com
Fri Dec 8 04:12:00 GMT 2006


Hi,
 Like the #undef for macros , do we have a way for undefining a
library function like say memset. Do we have any way(like linker) so
that my function memset(with different arguments) are used everywhere
instead of library function memset. One way would be to rename my
function memset to mymemset or #define it . But i want to know whether
there is any hack or anything so that the library is included but the
memset used is mine instead of the library version.


Yes here is some code.
#include<stdio.h>
#include<string.h>

int L[10][10];

#undef memset
/* if i include string.h it is compilation error, If i don't include i
get warning saying conflicting types in library function . One way
would be #define memset to mymemset or some other function but can it
not be done any other way like
hiding particular function symbol from library using linker and then
using this custom
version
*/
void memset(void *mem,int c, int len);
void memset(void *mem,int c, int len)
{

       int *ptr=mem;
       while(len--)
               *ptr++=c;

       return;
}


int main()
{
       int n=10,i,j,k,ll=-200;
       memset(L,2,100);
}


Regds
Nik



More information about the Binutils mailing list