Skip to content

Instantly share code, notes, and snippets.

@mikhailramalho
Created January 13, 2016 10:57
Show Gist options
  • Save mikhailramalho/6371f1698c6a24e37eb9 to your computer and use it in GitHub Desktop.
Save mikhailramalho/6371f1698c6a24e37eb9 to your computer and use it in GitHub Desktop.
unsigned int calc_size(unsigned int size)
{
return size*2;
}
void VLA_size(unsigned int size)
{
int arr[calc_size(size)];
arr[calc_size(size)-1] = 1;
assert(arr[calc_size(size) - 1] == 1);
}
int main()
{
unsigned int x = calc_size(3);
int arr1[calc_size(2)];
int arr2[calc_size(2)];
arr1[3] = 1;
arr2[3] = 1;
assert(arr1[calc_size(2) - 1] == 1);
assert(arr2[calc_size(1) + 1] == 1);
VLA_size(1);
VLA_size(0); // ERROR
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment