C compiler issue perhaps?

Doug Hardie bc979 at lafn.org
Fri Mar 14 22:10:43 UTC 2008


I have a program I was testing with gdb.  I was trying to figure out  
why c.rmonths was always zero when it should have been 6.  Stepped  
through using the gdb n command.  Here is the output:

(gdb)
215				c.rmonths = (edate - tdate) / toMONTHS;
(gdb)
223			c.dial_in = u.dial_in[0];
(gdb)
224			c.dsl = u.dsl[0];
(gdb) p c.rmonths
$1 = 0
(gdb) p c
$2 = {fa = 0, pwp = 0, disp_email = 0, imonths = 0, rmonths = 6,
   type = 73 'I', cd = 0 '\0', dial_in = 82 'R', dsl = 0 '\0',
   dsl_kit = 0 '\0', ip = 0 '\0', domain = 0 '\0', n_domain = 0 '\0',
   renewal = 89 'Y', program = "I\000\000"}
(gdb) p c->rmonths
$3 = 6
(gdb) p c.rmonths
$4 = 6


Notice, the first time i print it its zero.  The second time its 6.   
What gives here?  I have seen this before but couldn't pin it down.   
The program is not compiled with any optimization.  It is in a shared  
library though.


More information about the freebsd-questions mailing list