Xref: utzoo comp.lang.c:17143 comp.unix.xenix:5425 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!melpar!toppin From: toppin@melpar.UUCP (Doug Toppin) Newsgroups: comp.lang.c,comp.unix.xenix Subject: cc treats third level of struct differently? Keywords: cc bit-fields structs Message-ID: <193@melpar.UUCP> Date: 23 Mar 89 23:52:59 GMT Distribution: usa Organization: E-Systems, Falls Church, VA Lines: 67 We have a problem with a far pointer to a variable that has three levels of structures in it with the innermost defining a bit field. It works fine with fewer levels. I did not think that the level of embedded struct caused a different compiler action. Does anyone know what is wrong? I can find no reference to anything like this in my manuals. The smallest source that duplicates the problem follows. thanks Doug Toppin uunet!melpar!toppin /* Are three or more levels of structure depth combined with bit field definitions implied to be resolved with near pointers? We are running IBM Xenix 2 on a 286 and are having a problem that appears as if the compiler forces near pointers as deeper embedded structures are found. This creates three types, each contained within the next, it then defines a pointer to the type. The innermost structure has one variable that is 8-bits wide. Memory is allocated using 'brkctl' (which returns a far (32-bit) pointer). The 'brkctl' has nothing to do with the problem. It is only included for completeness. This is compiled with: cc -Me brkctl.c -o brkctl When this compiles the following error is returned: brkctl.c(54) : warning 60: conversion of a long address to a short address The error is the assignment line: tmp->level2.level3.a = 1; This error is generated by the compiler only if there is a bit field definition in the third or greater depth level. */ #include #include typedef struct { struct { struct { unsigned int a : 8; /* note bit field definition */ } level3; } level2; } DATA; DATA far *tmp; DATA far *brkctl(); main() { tmp = brkctl(BR_NEWSEG, 64000L, (char *) 0); /* allocate memory */ if (tmp == (DATA far *) -1) { fprintf(stderr, "Memory not available\n"); exit(1); } tmp->level2.level3.a = 1; } /* main */