fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. // problem: var6 becomes -1 inside func2 during the use of the inner for loop
  6.  
  7. #define N1 7
  8. #define N2 6
  9. #define N3 10
  10.  
  11. void func1()
  12. {
  13. // do stuff
  14. }
  15.  
  16. void func2(int var1[], int var2[], int var3[][N2], int var4[])
  17. {
  18. int i, j;
  19.  
  20. for (i = 0; i < N3; i++)
  21. {
  22. for (j = 0; j < N2; j++) // this line here is where var6 goes from 0 to -1
  23. {
  24. // stuff
  25. }
  26. }
  27.  
  28. // more code here
  29. }
  30.  
  31. int main()
  32. {
  33. srand(time(NULL));
  34.  
  35. // i have completely commented out this function call and foo still is changed.
  36. // left it in just in case
  37. func1();
  38.  
  39. int var1[N1];
  40. int var2[N1];
  41. int var3[N1][N2];
  42. int var4[N1];
  43.  
  44. // int foo; // if foo is declared then the problem does not occur
  45.  
  46. // if var5 and var6 are declared after func2 then var6 does not become -1
  47. int var5[1000];
  48. int var6 = 0;
  49.  
  50. func2(var1, var2, var3, var4);
  51.  
  52. // more code
  53. }
Success #stdin #stdout 0s 2152KB
stdin
Standard input is empty
stdout
Standard output is empty