memory...bytes.....c....but?
Posted: Mon Aug 22, 2005 8:47 am
how would i say...copy 4096 bytes of data from pointer dest, to pointer src? and explaination would be really nice
The Place to Start for Operating System Developers
https://f.osdev.org/
Code: Select all
for(size_t i = 0 ; i < NUMBYTES ; ++i)
destination[i] = source[i];
Code: Select all
__asm__ ("rep\n\t"
"movsb\n\t" : : "eDi"(destination), "eSi"(source), "ecx"(NumBytes));
Code: Select all
typdef unsigned int size_t;
void* memcpy( char *dest, const char *src, size_t n )
{
size_t i;
for ( i = 0; i < n; i++ )
dest[i] = src[i];
return dest;
}
Code: Select all
int a = 5; // a is now == 5
int *b = &a; // b is now pointing to a
int **d = &b; // d is now a pointer to a pointer. *d == b and **d == a.
printf("%i %i %i", a, *b, **d ); // prints three 5's.
a = 2; // everything points to a, so this will change the output for everything.
printf("%i %i %i", a, *b, **d ); // prints three 2's.
printf("%p", b ); // prints b which is a pointer to a.
// So, it's printing the memory location of a.
printf("%p", d ); // prints d which is a pointer to b.
// So, it's printing the memory location of b.
printf("%p", *d ); // prints *d which is the value of b which is a pointer to a.
// So, it's printing the memory location of a.
shouldent it be *dest = *src?
and, is size_t important or can it be int i?