Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 560 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Anonymous union within struct not in c99?

#1
here is very simplified code of problem I have:

<pre>
enum node_type {
t_int, t_double
};

struct int_node {
int value;
};

struct double_node {
double value;
};

struct node {
enum node_type type;
<b>union {
struct int_node int_n;
struct double_node double_n;
};</b>
};

int main(void) {
struct int_node i;
i.value = 10;
struct node n;
n.type = t_int;
n.<b>int_n</b> = i;
return 0;
}
</pre>

And what I don't undestand is this:

<pre>
$ cc us.c
$ cc -std=c99 us.c
us.c:18:4: warning: declaration does not declare anything
us.c: In function ‘main’:
us.c:26:4: error: ‘struct node’ has no member named ‘int_n’
</pre>

Using `GCC` without `-std` option compiles code above without any problems (and the similar code is working pretty well), but it seems that `c99` does not permit this technique. Why is it so and is it possible to make is `c99` (or `c89`, `c90`) compatible? Thanks.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through