bluejack <bl******@gmail.comwrites:
On May 28, 4:23 am, CBFalconer <cbfalco...@yahoo.comwrote:
>You didn't show a complete compilable program, in particular you
omitted the call to set_default_values, the declaration and
initialization of t, etc.
I know, I was looking for conceptual guidance; which Keith provided.
>My guess is that you never allocated data space for t.
Looked like a memory smash to me, too, and I actually spent some time
looking at that; but it turned out to be a display issue in an older
(but "current" according to yum) version of gdb.
The actual bug that surfaced in execution turned out to be
elsewhere... I was pursuing a red herring because it *looked* so
wrong.
Lesson learned: don't always trust your tools; but be careful about
which tool you blame. (I had been thinking it might be a compiler bug,
although I was skeptical, because in my experience it's *never* a
compiler bug; which was why I posted here...)
Another lesson: try narrowing your program down to a small
self-contained program that exhibits the problem. In your case, you
could have wrapped the declarations you posted with another dozen or
so lines of code, creating a small program that calls your
initialization routine and prints the values of the members of the
structure using printf. This is especially useful if your debugger
isn't being as helpful as it should. If the problem is in your code,
you're likely to figure it out while narrowing it down. If you still
don't know where the problem is, you can post the code here; if it's
portable C, we can probably let you know whether the code is behaving
as it should according to the standard.
<OT>Since it apparently turned out to have been a gdb bug, do a Google
search, or check the change log in the latest gdb release, to find out
whether it's been fixed, and in what release.</OT>
There's another possibility that I should have mentioned. You're
using long long, which is a new feature of C99. C99 conformance is
incomplete in most implementations. Since the compiler and the
runtime library are often provided separately, it's entirely possible
for the compiler to support long long, but for printf not to support
the "%lld" format. In this case, you can convert the value to long if
it happens to be in range, or roll your own conversion routine. (That
didn't turn out to be the problem in your case, but others might find
this helpful.)
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"