Last active
January 16, 2023 14:41
-
-
Save agagniere/666a141b24586fa39a8e13218071be5a to your computer and use it in GitHub Desktop.
Demonstrate
This file contains 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
#include <stdio.h> | |
#define C_ARRAY_LENGTH(A) (sizeof(A) / sizeof(*(A))) | |
void print_memory(const void* addr, size_t size); | |
const char config[][8] = { | |
"Hello", | |
"Salut", | |
"Hola", | |
"Gutentag", | |
"Nihao" | |
}; | |
int main() | |
{ | |
const size_t length = C_ARRAY_LENGTH(config); | |
for (int i = 0; i < length; i++) | |
printf("%.8s\n", config[i]); | |
printf("\n"); | |
print_memory(config, sizeof(config)); | |
printf("\n"); | |
if (0) | |
{ /* Segfaults */ | |
char** fail = (char**)config; | |
for (int i = 0; i < length; i++) | |
printf("%.8s\n", fail[i]); | |
} | |
else | |
for (char* line = (char*)config; line < (char*)config + sizeof(config); line += sizeof(*config)) | |
printf("%.8s\n", line); | |
return 0; | |
} |
Author
agagniere
commented
Jan 16, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment