dive_trip_list & dive_table

Amit Chaudhuri amit.k.chaudhuri at gmail.com
Mon Apr 15 07:04:56 PDT 2013


Dirk,

thanks for the clarification.

Alt_theory: maybe the Qt ui is being initialised before the dive_table is
written.

I *think* a global struct dive table would be initialised to contain PODs
with zero value, right [1] ? This might explain my first symption of nr ==
0.

Similar argument for dive_trip_list which is a pointer variable at global
scope, so I assume also guaranteed to be initialised to zero.

A

[1] K&R second edition section 4.9 initialization. Wish there was a 3rd
edition to add to my library.


On Mon, Apr 15, 2013 at 2:40 PM, Dirk Hohndel <dirk at hohndel.org> wrote:

> Amit Chaudhuri <amit.k.chaudhuri at gmail.com> writes:
>
> > Hi all,
> >
> > I'm trying to amend my Qt treeview to show dives from the xml data in
> > subsurface.  My current test dive set is grouped as 5 dives in 2 trips.
> >
> > When I query the members of struct dive_table from my mainwindow.cpp in
> > qt-gui/ I get a surprising result:
> >
> > int nr == 0
> > int preexisting == 0
> > int allocated == 0
>
> That should read 10, 10 and a few more.
>
> > I was at least expecting nr == 10
> >
> > I also checked the address of struct dive_table using printf("....%p")
> both
> > at my point of use and in parse_xml_buffer and they agree.
> >
> > So my theory is that dives in trips are possibly stored in another place
> > and I have dive_trip_list as the likely candidate.
>
> Nope. That has the two trips - from there you can get to the dives as
> well, but that's not how you should traverse them (as you could have
> dives that aren't in trips).
>
> > So, grep -r -n '*dive_trip_list' *.c *.h and I get 4 hits.
> >
> > 1) a comment
> > 4) extern decl
> > 2) divelist.c:57 dive_trip_t *dive_trip_list;
> > 3) divelist-gtk.c:62 dive_trip_t *dive_trip_list;
> >
> > Is the duplication of dive_trip_list a bug? Should one of these be
> extern?
> > If it's not a bug, how does C handle a duplicate declaration like this?
>
> One of them should indeed be extern - oops.
>
> > Is my theory right that dives in trips are moved out of tive_table into
> > dive_trip_list?
>
> The TRIPS are indeed in dive_trip_list. But the dives should all be in
> dive_table.
> My only explanation is that I did something similarly stupid with
> dive_table (but then I have no explanation why it works on the Gtk
> side).
>
> > When I try and read the value of dive_trip_list I am getting a NULL
> > pointer. I think this is an order of initialisation thing. I seem to have
> > the right address but at the point in time I query it it hasn't been
> filled
> > in.
> >
> > Tomaz - you may come across this when trying to populate your cylinder
> > info.  [I came across this after looking at the start of your
> > MainWindow::on_actionClose_triggered() ]
>
> I'll try to debug that in the next few hours.
>
> /D
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20130415/5ae9b00f/attachment.html>


More information about the subsurface mailing list