Results from unary operator * and &

for the unary operator * the operand should be a pointer to complete type, like
*int, *(*void), *(*int) in form of *(pointsTo)
result should be object…are we supposed to return the type of int, void* and *int (return pointsTo.getType???) in these three cases respectly?

for the & operator, like if we have &(int a), &(*char), are we supposed to return a *int and **char type??? so in these cases , it makes sense to make a constructor for pointerType with the his property pointsTo (here should be intType and IntegerPointerType)?
Thanks in advance!

If you’re asking about result types, your examples for * are correct.
For &, what you wrote does not make any sense, syntactically.
Assuming, however, that you mean &a where a has type int and &cp where cp has type char*, it would be correct.

Keep in mind though that these are only positive examples and there are conditions that need to be satisfied before you can return anything.

1 Like

yes, i mean the result types…
for the & operator, then we only need to check if the operand is a complete type and also if it is a L-Value (variable or pointer to a complete Type)…like &int, &char*, return types should be int and char* respectively…
so we do not need to consider the condition of the result that it should be pointer on page 16…just confused about it


condition of the result

the result is not a condition. If the conditions on the operand are met, then the result type is a pointer (in the case of &), otherwise, the expression is ill-typed.

1 Like