Hi all,
I have a simple code below
#include <stdio.h>
#include <string.h>
typedef struct {
int apn_in_use;
} bts_pdn_con_t;
typedef struct _bts_pdn_con_list_t_slot {
bts_pdn_con_t conn;
struct _bts_pdn_con_list_t_slot *next, *prev;
} bts_pdn_con_list_t_slot;
typedef struct {
bts_pdn_con_list_t_slot *head, *tail;
} bts_pdn_con_list_t;
typedef struct {
int umsi;
bts_pdn_con_list_t connections;
} bts_ue_t;
int funct(bts_ue_t *ue)
{
bts_pdn_con_t *conn = 0;
conn = malloc(sizeof(bts_pdn_con_t));
printf("value of umsi is %d\n", ue->umsi);
printf("value of apn is %d\n", conn->apn_in_use);
return 1;
}
int main()
{
bts_ue_t ue;
memset(&ue, 0, sizeof(ue));
bts_pdn_con_list_t_slot bts_slot;
memset(&bts_slot, 0, sizeof(bts_slot));
bts_pdn_con_t *conn = &bts_slot.conn;
ue.umsi = 1;
conn->apn_in_use = 2;
printf("value of apn is %d\n", conn->apn_in_use);
funct(&ue);
return 1;
}
In that function, I assign umsi with 1, and apn_in_use with 2. When I pass it to funct(&ue), I got the value of umsi correctly, but for the apn, I got the wrong value (seems like garbage). How am I supposed to get the value of conn->apn_in_use in the function int funct(bts_ue_t *ue). I can only pass ue, but I need the conn->apn_in_use correctly..
thank you for the explanation