Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!boulder!sunybcs!bingvaxu!leah!rds95 From: rds95@leah.Albany.Edu (Robert Seals) Newsgroups: comp.sys.ibm.pc Subject: Structure spans a segment, huge pointer to structures. Keywords: C, huge pointer, segmented architecture, ugh. Message-ID: <1705@leah.Albany.Edu> Date: 21 Mar 89 19:29:26 GMT Organization: The University at Albany, Computer Services Center Lines: 62 Yo - I have got a little question/problem. Suppose I declare a huge pointer to a structure that is larger than 16 bytes, and then far[mc]alloc a chunk of memory that is larger than 64k. No problem. Now suppose the struct looks like this... {char a; double b, c}. It would appear that the structure that borders the 64k line is going to have troubles if one of the doubles also borders the line - the address of the beginning of the double is in 1 segment, and at least part of it is in another. The following illustates... #include #include typedef struct { char a; double b, c;} rec; /* 17 bytes with tc 1.5 */ void main() { rec huge *hp; int i; if ((hp = (rec huge *) farcalloc(sizeof(rec), 4000)) == NULL) { printf("No alloc\n"); exit(1); } /* * The address of the beginning of the chunk */ printf("%Fp\n", hp); /* * I picked '3850' here because if we use byte alignment, it * should die on #3855 or so. If you use word alignment, * it will be somewhat less... * * The loop should print * i, address of hp[i], 2.5, 3.5 */ for (i=3850; i<4000; i++) { printf("%d %Fp ", i, hp+i); hp[i].b = 2.5; printf("%lf ", hp[i].b); hp[i].c = 3.5; printf("%lf\n", hp[i].c); } farfree((void far *) hp); } On my system, Turbo C 1.5, byte alignment, I get a floating point error and either system hang or exit to command after it prints hp[3854].b. So, I know WHY it does this; the question is whether it is CORRECT behavior. Actually, the real question is why we don't have 32 bit pointers, which then leads to why Intel felt backward compatibility with 8085 was so inportant in 80286 and 386, and why aren't there any decent [read: cheap] 32 bit compilers, and then why are we still using DOS anyway? and why isn't GNU finished with a 386 kernel yet??? rob