Created
January 13, 2016 10:57
-
-
Save mikhailramalho/6371f1698c6a24e37eb9 to your computer and use it in GitHub Desktop.
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
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