Create a gist now

Instantly share code, notes, and snippets.

@scvalex /Makefile
Last active Aug 29, 2015

Variable Length Arrays in C
all: var_len_arrays.c
gcc -O1 var_len_arrays.c -S
#include <stdio.h>
void __attribute__ ((noinline)) exercise(int *arr, int n) {
int i;
for (i = 1; i < n; ++i) {
arr[i] = arr[i - 1] ^ arr[i];
}
}
void foo() {
int arr[10];
arr[3] = 1234;
exercise(arr, 10);
}
void bar() {
int arr[10];
int brr[12];
arr[3] = 1234;
brr[3] = 5678;
exercise(arr, 10);
exercise(brr, 12);
}
void baz(int n) {
int arr[n];
arr[3] = 1234;
exercise(arr, n);
}
void bam(int n) {
int arr[n];
int brr[n];
int crr[n];
int drr[n];
int err[n];
int frr[n];
int grr[n];
int hrr[n];
int irr[n];
int jrr[n];
int krr[n];
int rrr[n];
arr[3] = 1234;
brr[3] = 1234;
crr[3] = 1234;
drr[3] = 1234;
err[3] = 1234;
frr[3] = 1234;
grr[3] = 1234;
hrr[3] = 1234;
irr[3] = 1234;
jrr[3] = 1234;
krr[3] = 1234;
rrr[3] = 1234;
exercise(arr, n);
exercise(brr, n);
exercise(crr, n);
exercise(drr, n);
exercise(err, n);
exercise(frr, n);
exercise(grr, n);
exercise(hrr, n);
exercise(irr, n);
exercise(jrr, n);
exercise(krr, n);
exercise(rrr, n);
}
int main(int argc, char *argv[]) {
printf("Ok!\n");
return 0;
}
@scvalex
Owner
scvalex commented Jan 18, 2015

Blog post explaining this code: https://scvalex.net/posts/40/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment