Re: override memset...

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

 



y2bismil@xxxxxxxxxxxxxxxxxxxx writes:

> So just to confirm, if in a file say:
> 
> "myreplacements.c", I have
> *************************************************
> void * memset(void * s,char c,size_t count)
> {
>  /*my code*/
> }
> *************************************************
> 
> Then any call to memset WITHIN MY CODE will first be linked with this memset
> rather than the one in glibc?

Correct.

> This occus even if the calling file has included
> <string.h>?

Correct (well, unless memset is defined as a macro in <string.h>).

> Do I have to include a header of my own, say "myreplacements.h" in
> each file (i.e.  i could modify the make command to use -include myreplacements.h?

No.

In some cases, gcc may optimize away calls to memset, as you know.  If
you don't want to happen, you should use the -fno-builtin option.

I think that in some cases gcc may actually generate calls to memset
to zero out memory--I'm not certain about that, though I know that it
generates calls to memcpy.  Because of this, you should make sure that
your version of memset does in fact perform the correct operation, as
well as doing whatever else you want it to do.  Otherwise your program
may not behave correctly.

Ian

[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