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

Error on combination of typedef and variable length array in C language #91

Open
mnakao opened this issue Sep 28, 2018 · 0 comments
Open

Comments

@mnakao
Copy link
Member

mnakao commented Sep 28, 2018

For example, the result of processing the following code with C_Front is different from the result using gcc.

#include <stdio.h>
void test(int n){
  typedef int arrayN_t[n];
  n++;
  arrayN_t A;  // When n = 1, int A[1]
  int B[n]; // When n = 1. int B[2]
  printf("%d %d\n", sizeof(A), sizeof(B));
}
int main(){ test(1); return 0;}

While the result of gcc is "4 8", that of C_Front with gcc is "8 8".
Because, C_Front translates the above code to a following code,

void test(int n){
  typedef int arrayN_t[n];
  n++;
  int A[n];
  int B[n];
  printf("%d %d\n", sizeof(A), sizeof(B));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant