Created
June 30, 2014 14:13
-
-
Save Sebbyastian/80c5bd0f02926790f0da to your computer and use it in GitHub Desktop.
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
/* I hearby do solemnly declare this to be the most beautiful abuse of preprocessor macros and structs I've ever committed. */ | |
#define ARRAY_CAT(type, array, ...) (*(type (*)[sizeof (array) / sizeof (type) + sizeof ((type[]) { __VA_ARGS__ }) / sizeof (type)]) &(struct { type foo[sizeof (array) / sizeof (*array)]; type bar[sizeof ((type[]) { __VA_ARGS__ }) / sizeof (type)]; }) { .foo = array, .bar = { __VA_ARGS__ } }) | |
#include <stdio.h> | |
int main(void) { | |
const int array_1[] = { 0, 1, 2, 3 }; | |
const int array_2[] = ARRAY_CAT(int, array_1, 4, 5, 6, 7, 8); | |
const int array_3[] = ARRAY_CAT(int, array_1, 10, 11, 12); | |
printf("%zu %zu %zu\n", sizeof array_1, sizeof array_2, sizeof array_3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment