Skip to content
New issue

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

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

Already on GitHub? # to your account

struct members declared as unbounded arrays don't seem to work #25

Open
pgbovine opened this issue Oct 25, 2019 · 2 comments
Open

struct members declared as unbounded arrays don't seem to work #25

pgbovine opened this issue Oct 25, 2019 · 2 comments
Labels

Comments

@pgbovine
Copy link

(NB: is this just because i'm using C11 and not a newer dialect?)

examples:

struct aaa {
   int a;
   char flag;
   char buf[]; // works if this is commented out or has a number inside [], or "char* buf;"
};

int main() {
    struct aaa x = {1, 2};
    return 0;
}

---
struct my_struct {
  int n;
  char s[]; // works if this is commented out or has a number inside [], or "char* s;"
};

int main() {
  struct my_struct *s = malloc(sizeof(struct my_struct) + 50);
}
---
#include <stdlib.h>

struct flex {
  size_t count;
  double average;
  double scores[]; // works if this is commented out or has a number inside [], or "double* scores;"
};

int main() {
  struct flex *pf1;
  pf1 = malloc(sizeof(*pf1));
  return 0;
}
@pgbovine
Copy link
Author

a possibly-related example in C++ class (instead of struct) definition:

template<typename T>
class Node{
private:
  T data;
  Node<T>* children[]; // problem here! works if [] -> [10] (or any number) or "Node<T>** children;"
public:
  Node(T data, char size) {
    data = data;
    for (char i = 0; i < size; i++) children[i] = 0;
  }
};
int main() {
  Node<int> node = Node<int>(5, 10);
  return 0;
}

@pgbovine
Copy link
Author

pgbovine commented Nov 9, 2019

Maybe relevant or maybe not?
https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html

@pythontutor-dev pythontutor-dev transferred this issue from another repository Jun 28, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants