enum value changes when passing into function
Hi,
I am experiencing a strange behavior when using enum.
My enum is as follows:
Code:
typedef enum {
L_R = 0,
L_I,
L_L,
}S_LEVEL;
Next, I have a structure, and I am using this enum as type for one member of this structure:
Code:
typedef struct SV {
int s_id;
int s_p;
int s_b;
S_LEVEL s_lvl;
int s_u;
int s_d;
}sv_t, *s_ptr;
Next step is when I fill the structure SV.
Code:
void a_function() {
sv_t sv;
s_ptr svp;
sv.s_id = 45;
sv.s_p = 35;
sv.s_b = 400;
sv.s_lvl = L_L; // this must be 2
sv.s_u = 2;
sv.s_d = 3;
/*************************************/
/* FIRST PRINT */
/*************************************/
printf(" server %d level is %s \n", sv.s_id, (sv.s_lvl == L_L ? "level is L" : ((sv.s_lvl == L_I) ? "level is I" : "level is R"));
svp = &sv;
b_function(svp)
}
Code:
void b_function(s_ptr s) {
/*************************************/
/* SECOND PRINT */
/*************************************/
printf(" adding an item .... \n");
printf(" server %d level is (%d, %s) \n", s->s_id, s->s_lvl, (s->s_lvl == L) ? "level is L" : ((s->s_lvl == I) ? "level is I" : "level is R"));
}
Here is what I receive as output:
// First print
server 45 level is L_L
which is correct
// Second print
server 45 level is (0, L_R)
which is wrong
Why is this value changing ?
thanks,
Zahid