4

I have the following structures:

struct sched_param {
    union {
        int sched_priority;
        struct lshort_sched_param lshort_params;
    };
};

struct lshort_sched_param {
    int requested_time;
    int level;
};

Whenever I make a sched_param param1 structure and try to update the param1.sched_priority field I get the message written in the topic.

struct sched_param param1;
param1.sched_priority = 1;

But, whenever I make a sched_param param2 and try to update the param2.lshort_params.level it works good.

struct sched_param param2;
param2.lshort_params.level= 1;

What could be the reason?

Nadav Peled
  • 951
  • 1
  • 13
  • 19

2 Answers2

3

It is because the version of the gcc compiler you are using does not support unnamed union. See this stackoverflow link

Community
  • 1
  • 1
helloV
  • 50,176
  • 7
  • 137
  • 145
3

Your union should have a name, for instance

struct sched_param {
    union {
        int sched_priority;
        struct lshort_sched_param lshort_params;
    } union_member_name;
};

and then you can use param1.union_member_name.sched_priority

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97