Alf P. Steinbach wrote:[color=blue]
> *
PapaTodd@gmail.com:[color=green]
> >
> > I've been fighting with this issue all day. This code is tried and
> > true on other OS's, but when I compile and test on AIX 5.3 using xlC_r,
> > I have problems.
> >
> > Here is the code snippets giving a problem:
> >
> >
> > main.cpp
> > ---------------------------------
> > mySchemaType *theSchema = NULL; // declared as global[/color]
>
> That's the first problem, and the solution is: DON'T USE GLOBAL
> VARIABLES.
>
>
>[color=green]
> > // within main()
> > theSchema = prepareSchemaAndFilters(some strings showing files);
> >
> > pRecord = theSchema->records;
> > pField = pRecord->fields;
> > mySpecificType *tmpRecord = (mySpecificType *)pField->specific;[/color]
>
> That's a second problem: you're doing a reinterpret_cast using C
> notation so you don't know what it is, and the solution is: USE C++
> STYLE CASTS IF YOU ABSOLUTELY MUST CAST.
>
> And the casting is a third problem, for which the solution is DON'T USE
> CASTS.
>
>[color=green]
> > printf("the specific db_type = %s\n",tmpRecord->db_type);[/color]
>
>
>[color=green]
> > ----------------------------------
> > At this point, db_type is shown to be garbage.[/color]
>
> Not surprising; see above.
>
>[color=green]
> > This is my problem.
> > Here is what prepareSchemaAndFilters looks like:
> >
> > makeschema.c
> > ----------------------------------
> > mySchemaType *prepareSchemaAndFilters(the file strings)
> > {
> > mySchemaType *theSchema;
> > // code removed for clarity, essentially items are put into theSchema
> > myRecordType *pRecord = theSchema->records;
> > myFieldType *pField = pRecord->fields;
> > mySpecificType *tmpRecord = (mySpecificType *)pfield->specific;
> > printf("the specific db_type = %s\n",tmpRecord->db_type);
> >
> > return theSchema;
> > }[/color]
>
> You don't show enough code to diagnose the technical problem, in
> particular you don't show the earlier assignment to 'pfield->specific'.
>
> Why did you think the relevant code would not matter?
>
> However, what you show is enough to diagnose the real problem, which is:
> assembly language level coding (expressed in C or C++ doesn't matter).
>
> [snip][color=green]
> > So, finally to the source of my problem. When I am within mes_schema.c
> > (linked in as a library), I can cast the void* as a specific* and get
> > the different values. When I am back in main.cpp, if I do this, the
> > values that are part of specific* print correctly.[/color]
>
> ?
>
> Anyway, sound like you have a pointer pointing to deallocated storage,
> nowhere in particular, or the stack.
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?[/color]
My general excuse for some of the sloppy coding is that it is
inherited. Not that I'm a great programmer, but... anyway, moving
forward.
First test: change the returned variable theSchema to a local. Didn't
help.
Second test: change the void* to specific* in the structure
declaration. Didn't help.
So I'm beginning to think that the problem is that the original setting
of the values isn't being handled well, and it is just luck that it
worked on all of our other products/platform combinations.
I don't want this to turn into a "fix my program one step at a time for
me", so I'm going to spend another day debugging it tomorrow. The code
that initially sets the values that are read from the file appear to be
correct at first glance, doing things such as allocating memory, then
setting the values, or duplicating the strings via an inline function.
Thanks for your help,
Todd