I am a newbie in C. My problem is quite simple. Below is my code. I expect it to increase req_id by 1 and then pint out 1. However, the result is 0.
typedef uint32_t req_id_t;
typedef struct view_stamp_t{
req_id_t req_id;
}view_stamp;
struct consensus_component_t{
view_stamp highest_seen_vs;
};
typedef struct consensus_component_t consensus_component;
static void view_stamp_inc(view_stamp vs){
vs.req_id++;
return;
};
int main()
{
consensus_component* comp;
comp = (consensus_component*)malloc(sizeof(consensus_component));
comp->highest_seen_vs.req_id = 0;
view_stamp_inc(comp->highest_seen_vs);
printf("req id is %d.\n", comp->highest_seen_vs.req_id);
free(comp);
return 0;
}