Funny behavior under TURBO compiler
Anonymous NNTP Posting
anon at rouge.usl.edu
Sat Mar 23 04:54:57 AEST 1991
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 at usl.edu)
%%%%%%%%%%%%%%%%%%%%%%%%% CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include <stdio.h>
#include <alloc.h>
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 %%%%%%%%%%%%%%
More information about the Comp.lang.c
mailing list