As @chux advised me I copy & paste my comment as the answer to my question. Actually it is a kind of lessons learned.
I found out that the code compiled by make clean; make is different of the code compiled by make clean; make debug which adds all the flags for debugging. The results for the former are the expected whereas the null pointer reference is obtained in the later case. So I think we can finish this question by pointing that using valgring and gdb is a good choice in order to solve the problem I posed.
Thanks a lot!