pythontutor-dev / pythontutor

10 stars 4 forks source link

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

Open pgbovine opened 5 years ago

pgbovine commented 5 years ago

(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 commented 5 years ago

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 commented 4 years ago

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