This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Over-riding GCC's builtin functions
- From: bd satish <bdsatish at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 6 Sep 2009 23:14:11 +0530
- Subject: Over-riding GCC's builtin functions
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