fix: issue #2, for real this time

This commit is contained in:
Joseph Poirier 2015-06-13 13:27:01 -05:00
parent e8b2139b26
commit 6132405404
3 changed files with 45 additions and 8 deletions

View file

@ -635,6 +635,7 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
{ {
struct Value *Result; struct Value *Result;
union AnyValue *ValPtr; union AnyValue *ValPtr;
struct ValueType *Typ;
#ifdef DEBUG_EXPRESSIONS #ifdef DEBUG_EXPRESSIONS
printf("ExpressionPrefixOperator()\n"); printf("ExpressionPrefixOperator()\n");
@ -663,11 +664,12 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
case TokenSizeof: case TokenSizeof:
/* return the size of the argument */ /* return the size of the argument */
if (TopValue->Typ == &Parser->pc->TypeType) if (TopValue->Typ == &Parser->pc->TypeType)
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Val->Typ, Typ = TopValue->Val->Typ;
TopValue->Val->Typ->ArraySize, true));
else else
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ, Typ = TopValue->Typ;
TopValue->Typ->ArraySize, true)); if (Typ->FromType != NULL && Typ->FromType->Base == TypeStruct)
Typ = Typ->FromType;
ExpressionPushInt(Parser, StackTop, TypeSize(Typ, Typ->ArraySize, true));
break; break;
default: default:
/* an arithmetic operator */ /* an arithmetic operator */

View file

@ -1,12 +1,43 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
char a; char a;
int b; int b;
double c; double c;
struct P1 {
int a;
int b;
double c;
};
struct P2 {
int a;
int b;
int c;
int d;
double e;
};
struct P3 {
int a;
int b;
int c;
int d;
double e;
struct P1 *p1;
struct P1 *p2;
struct P1 *p3;
};
void main() {
struct P1 *p1;
struct P2 *p2;
struct P3 *p3;
printf("%d\n", sizeof(*p1));
printf("%d\n", sizeof(*p2));
printf("%d\n", sizeof(*p3));
printf("%d\n", sizeof(a)); printf("%d\n", sizeof(a));
printf("%d\n", sizeof(b)); printf("%d\n", sizeof(b));
printf("%d\n", sizeof(c)); printf("%d\n", sizeof(c));
}
void main() {}

View file

@ -1,3 +1,7 @@
16
24
48
1 1
4 4
8 8