Over-riding GCC's builtin functions

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

 



Hello,

    I wrote my own version of memchr( ) but looks like it is clashing
with GCC's builtin function of same name. I'm not able to set any
breakpoint.
How should I over-ride this ?

Here is the code I wrote:
----- memchr.cpp ----
void* memchr(const void* str,  int ch, size_t count)
{
    unsigned char* buf = (unsigned char*)str;
    unsigned char  c   = ((unsigned char)(ch));
    register unsigned int i;

    for(i=0; i<count; i++)
    {
        if(*buf == c)            return (void*)buf;
        buf++;
    }
    return NULL;
}
I compiled the above like:
g++ -c -g -Wall -ansi -nostdinc -nostdinc++ -fno-builtin
fno-nonansi-builtins -Wshadow memchr.cpp

And to test the above code, here is a simple main( )
--- test_memchr.cpp ---
int main( )
{
    const char msg[ ] = "Hello World";
    char x; char *c=&x;

    c = (char*)memchr(msg, 'X', 10);
    return *c;
}

The above was compiled as

g++  -g -Wall -nostdinc++ -nostdinc -fno-builtin test_memchr.cpp memchr.o

The program gives a segmentation fault ! And I can't put a breakpoint
even though "-g" is specified.

My guess is that I'm somewhere calling GCC's in built memchr instead
of mine. Can somebody help me where am I going wrong ?

-- Satish.BD

[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