Re: Compiler error for "wrong" sized type
- From: "S.Tobias" <siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: 12 May 2006 21:57:05 GMT
tedu <tu@xxxxxxxxxxxxx> wrote:
David White wrote:Nit: a label reqires a following statement; make it:
Richard Heathfield wrote:
Well, I don't know about "better", but I like this:
char DetectWrongSize[(sizeof(struct my_struct) == correct_size) * 2 -
1];
If the struct is the wrong size, this will yield a negatively sized
array, which is illegal.
Thanks. That's an improvement. Unfortunately, our Hi-Tech compiler doesn't pick it up
because it treats an array size of -1 as unsigned!
does it allow multiple case statements with the same value?
switch (0) {
case sizeof(struct my_struct) == correct_size:
case 0:
}
switch (0) {
case sizeof(struct my_struct) == correct_size: ;
case 0: ;
}
(Otherwise it's a nice trick, I liked it.)
--
Stan Tobias
mailx `echo siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx | sed s/[[:upper:]]//g`
.
- Follow-Ups:
- Re: Compiler error for "wrong" sized type
- From: Harald van Dijk
- Re: Compiler error for "wrong" sized type
- References:
- Compiler error for "wrong" sized type
- From: David White
- Re: Compiler error for "wrong" sized type
- From: Richard Heathfield
- Re: Compiler error for "wrong" sized type
- From: David White
- Re: Compiler error for "wrong" sized type
- From: tedu
- Compiler error for "wrong" sized type
- Prev by Date: Re: Array and Pointer Tutorial
- Next by Date: Re: swapping bytes in an integer
- Previous by thread: Re: Compiler error for "wrong" sized type
- Next by thread: Re: Compiler error for "wrong" sized type
- Index(es):
Relevant Pages
|