I am doing work for and OS class and for some reason bcc needs a memcpy even though I haven't called it in the code and its unavailable, so I'm rolling my own, however it keeps segfaulting `
void memcpy( void* destination, void* source, size_t bytes )
{
size_t i = 0;
char* destination__ = ( char* ) destination;
char* source__ = ( char* ) source;
if( !( destination__ == source__ ) )
{
for( ; i < bytes; ++i )
destination__[ i ] = source__[ i ];
}
}
It seems to segfault and I am not sure why, it does fine when things are malloced but not for something like the following.
`
char* foo = "Hello";
char* bar = "Goodbye";
memcpy( bar, foo, 5 );
I have a feeling this is because foo and bar are likely global data, and it has something to do with that but Im not sure. I wouldent be asking except for the fact that I have found other implementations that are the same/similar online elsewhere. It crashes when compiled with regular ol' gcc which Im using to validate outside the OS Im building that has no diagnostics. Im confused as to why this is happening.