oversized struct and weird DC10.72 behaviour
"Tito" <[email protected]>
| Newsgroups | gmane.comp.hardware.rabbit-semiconductor |
|---|---|
| Message-ID | <[email protected]> |
IMHO the following code should not compile:
#define MAX_QSIZE 258
typedef struct {
byte data[255];
} a_type;
typedef struct {
a_type data[MAX_QSIZE];
} b_type;
far b_type b;
main () {
printf("%d\n", sizeof(b));
}
258 * 255 = 65,790 > 32,767 bytes
On the contrary, such an oversized struct can definitely be defined and
used at runtime, with no errors or warnings from the compiler, but with
possible memory corruption problems. Look at the .map file: only 254 (=
65790 & 0xffff) bytes are allocated for "b"
Strange, isn't it? My code is obviously wrong , but in my opinion the
compiler should behave more consistently.
E.g. the following code in fact does not compile:
#define MAX_QSIZE 129
typedef struct {
byte data[255];
} a_type;
typedef struct {
a_type data[MAX_QSIZE];
} b_type;
main () {
printf("%d\n", sizeof(b_type));
}
With the expected compiler messages:
line 12 : ERROR UNTITLED1.C : Object too large for sizeof.
line 12 : ERROR UNTITLED1.C : Internal error: Invalid object storge
(check void type).