I wonder why after my malloc all modifications aren't working. Here is the code I used to illustrate this :
#include <stdio.h>
#include <stdlib.h>
struct Age {
unsigned int age : 16;
unsigned int two : 2;
unsigned int notToBeInitialed: 2;
};
int init(struct Age * p){
p = (struct Age *) malloc( sizeof(struct Age) );
p->age = 5;
return 0;
}
int change(struct Age * p){
p->age = 99;
}
int getValue(struct Age * p){
return p->age;
}
int main(void) {
struct Age test;
init(&test);
printf( "Age.age : %d\n", getValue(&test) ); // gives me 0 , expected 5
change(&test);
printf( "Age.age : %d\n", getValue(&test) ); // gives me 99
return 0;
}
What have I done wrong ?
Thanks for your help.
Source : http://www.tutorialspoint.com/cprogramming/c_bit_fields.htm Ideone : https://ideone.com/O59tqZ