[C++-sig] Strange Behavior w/File Pointers

Michael Wieher michael.wieher at gmail.com
Fri Mar 7 22:24:07 CET 2008

Well, lucky for me each read is uniform length and they're sequential, so I
was able to handle the problem by seekg() to the index*len each time I call

I'm pretty sure the weirdest part was that, if I read in data to a structure
and then didn't do anything else, it behaved fine.

but if I read in data to a structure and then accessed members of that
structure, it got screwy.  Maybe it has to do with gnu's __attribute__ flag
or some strange combination of weirdness.

but thanks for the tips =)

2008/3/7, Raoul Gough <RaoulGough at yahoo.co.uk>:
> Michael Wieher wrote:
> > Yes I'm sure.
> >
> > I've written functions to write out from inside the C++ file to a text
> > file to check this, as well as getPtr functions that will export the
> > pointer's location to the python, and the results are the same.
> >
> > It doesn't happen EVERY call, but seemingly randomly. (1 in 15, 3 in
> > 10, etc.)
> >
> > Could there be strange binary characters that are read in that could
> > cause it to shift like that?
> Don't know - it sounds weird to me. I see you're opening the file with
> the ios::binary flag, so there shouldn't be anything reformatting like
> that happening. Anyway, didn't you say it always reads an integer
> multiple of the number of bytes you asked for? That wouldn't be
> explained by multibyte character conversions. It sounds more like the
> function being called unexpectedly, or something else manipulating the
> file - I guess you could rule that out by making the file a private
> member variable or something along those lines.
> All I can suggest is the usual stuff which you probably already know -
> check all return codes, error status values, and reduce the test case
> further and further until the problem goes away or it proves there's a
> problem in the library - e.g. split the actual file reading into a
> separate function with its own logging, and test that from plain C++
> code to rule out any weird Python/C++ interactions. Then maybe switch to
> std::streambuf interface or even stdio's FILE*, but it's hard to imagine
> there'd be a bug like that in the standard library that you're using.
> --
> Cheers,
> Raoul.
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080307/e9afafc6/attachment.htm>

More information about the Cplusplus-sig mailing list