Re: Undefine a library function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/7/06, Tim Prince <timothyprince@xxxxxxxxxxxxx> wrote:
Niklaus wrote:
> 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.
>

Do you have an example where #undef doesn't accomplish what you want?
Evidently, many standard C functions will have macro replacements in the
standard headers used in your implementation.  C standard requires
ability to put those aside with #undef and to have an underlying
separate library implementation, which you could attempt to preempt with
your own version.
It's common practice for compilers to #define memset() to a special
library version, but not with changes in the meaning of arguments.  If
your own version is not functionally compatible with the standard
version, you are inviting trouble by using the standard name.

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
*/
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);
}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux