Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppci-cc: conditional operator does not work with struct/union types #104

Open
tstreiff opened this issue Jul 1, 2020 · 0 comments
Open
Labels
C frontend Issues related to the C language compiler

Comments

@tstreiff
Copy link
Contributor

tstreiff commented Jul 1, 2020

typedef struct { int x, y; } point_t;

point_t origin = { 0, 0 };

point_t f1(point_t *p) {
  if (p) return *p;
  else return origin;
}

Compilation and execution are OK.

Same function, written differently:

point_t f2(point_t *p) {
  return p ? *p : origin;
}

It fails to compile:

14:  return pp ? *pp : origin;
               ^ Cannot determine type rank for 'Structured-type field_names=['x', 'y']'

The C standard lists all possible combinations for the 2nd and 3rd operands types:

  1. if one is struct/union type, the other shall be the same (our case)
  2. it one is void, the other shall be void
  3. if one is a pointer to a type T, the other may be of the same pointer type, or void * or 0/NULL
  4. if one is an arithmetic type, the other shall be an arithmetic type, and the usual arithmetic conversions apply (integer promotion, etc.) to find the common type
@windelbouwman windelbouwman added the C frontend Issues related to the C language compiler label Jul 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C frontend Issues related to the C language compiler
Projects
None yet
Development

No branches or pull requests

2 participants