Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove a couple of MSC_VER stuff
[simgrid.git] / tools / cmake / test_prog / prog_stackgrowth.c
1 /* Copyright (c) 2010, 2014-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 static int iterate = 10;
11 static int growsdown(int *x)
12 {
13   int y = (x > &y);
14
15   if (--iterate > 0)
16     y = growsdown(&y);
17
18   /* The stack sometimes changes at the 0th level. 
19    * Original version did fail in this case, but I changed this around SimGrid 3.13 because of https://bugs.debian.org/814272
20    * Every arch failed on that day :(
21    */
22   if (iterate != 0 && y != (x > &y)) {
23     fprintf(stderr, "The stack changed its direction! (Iteration: %d. It was growing %s; &y=%p; &prevY=%p)\n",
24             (10-iterate), y?"down":"up", &y, x);
25     exit(1);
26   }
27   return y;
28 }
29
30 int main(int argc, char *argv[])
31 {
32   int x;
33   printf("%s", growsdown(&x) ? "down" : "up");
34
35   return 0;
36 }