Identical types

Am I understand it right, that two types are identical iff they are exactly the same or one type is convertible to other?

For example:

char a = 'a';
int b = a;  // no error, because char is convertible to int, so they are identical in this case

// but

int c = 4;
char d = c;  // error, because int is not onvertible to char 
                   // and in this case they are not identical?

No, two types are identical if they are syntactically equal. Your example still typechecks because assignment does not require that both types are identical. It also type checks if both are integral, which int and char are.

1 Like

Your example still typechecks because assignment does not require that both types are identical.

On page 6 of project description states, that both operands in assignment should be identical. Or does it mean something else?

image

“One of” means that at least one of those has to be true. If “Both operands have integer type” is true, the program is well-typed, no matter what the other three points say.

You seem to be reading this as “all of”. This does not make sense, since then you would need things to have both integer and pointer types, which never happens.

Alternatively, your reading of “at least one, but point 1 is special and always needs to hold” also does not make sense, since point 1 then subsumes all the cases.

1 Like