Home/Support/Support Forum/Wrong handling of big struct size, possible compiler bug?
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Wrong handling of big struct size, possible compiler bug?

0 votes
Look at this code sample:

#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));
}


It compiles and runs, but something strange (and possibly dangerous) is obviously happening here: "b_type" should be too big to handle (258x255=65790) but the compiler is not complaining about it, and allocates 254 bytes for "b"

By the way: 254 = 65790 & 0xffff ...
asked Aug 14, 2013 in Rabbit by tito.brasolin New to the Community (4 points)

Please log in or register to answer this question.

1 Answer

+1 vote
 
Best answer
Yes, it is a bug .
answered Sep 12, 2013 by cpigilam Veteran of the Digi Community (655 points)
selected Sep 12, 2013 by tito.brasolin
...