Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!wuarchive!rex!rouge!anon From: anon@rouge.usl.edu (Anonymous NNTP Posting) Newsgroups: comp.lang.c Subject: Funny behavior under TURBO compiler Keywords: TURBO C++, local, global Message-ID: <27668@rouge.usl.edu> Date: 22 Mar 91 18:54:57 GMT Organization: Univ. of Southwestern Louisiana Lines: 52 Hi Netters, I am unable to understand the behavior of following program compiled under TURBO C++ compiler. This program prints numbers 1-12. When "TB2 tbl" declaration is local to main() (as shown) the program works fine and the results are printed as : 1 2 3 4 5 6 7 8 9 10 11 12 If I make "TB2 tbl" a global variable the results are: 10 11 12 10 11 12 10 11 12 10 11 12 What's wrong , I couldn't figure out... Anyone has clues.. Thanx, Rajiv (EMAIL: rxd0219@usl.edu) %%%%%%%%%%%%%%%%%%%%%%%%% CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #include #include typedef int *TB1[3]; typedef TB1 *TB2[4]; main() { int i, j, k=1; TB2 tbl; for (i = 0; i < 4; i++) for (j = 0; j < 3; j++) { if ( ((*tbl[i])[j] = (int *)malloc(sizeof(int))) == NULL) { printf("malloc error\n"); exit(1); } *((*tbl[i])[j]) = k++; } for (i = 0; i < 4; i++) for (j = 0; j < 3; j++) printf("%d ", *((*tbl[i])[j])); } %%%%%%%%%%%%%%%%%%%%% END OF CODE %%%%%%%%%%%%%%