Created
February 18, 2023 18:15
-
-
Save pavly-gerges/a78205ad769f370c822bc7cc9a9b8e7f to your computer and use it in GitHub Desktop.
Tests chunk memory copy in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Test chunk memcpy | |
* | |
* @author pavl_g | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
static inline void printAddresses(char* arr, int length) { | |
for (int i = 0; i < length; i++) { | |
printf("%p", &((arr)[i])); | |
printf("\n"); | |
} | |
} | |
static inline void printValues(char* arr, int length) { | |
for (int i = 0; i < length; i++) { | |
printf("%c", arr[i]); | |
} | |
printf("\n"); | |
} | |
int main() { | |
/* 20 bytes */ | |
const int length = 20; | |
char src[length]; | |
char dest[length]; | |
src[0] = 'a'; | |
src[1] = 'b'; | |
src[2] = 'c'; | |
src[3] = 'd'; | |
printAddresses(src, length); | |
printValues(src, length); | |
/* copy values [length] from src starting from index [2] to the | |
dest buffer starting from index [2] */ | |
memcpy(&dest[2], &src[2], length); | |
printAddresses(dest, length); | |
printValues(dest, length); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment