Archived

This topic is now archived and is closed to further replies.

Pointer structures in Borland C++

This topic is 5077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster
Well, gee, it's kinda hard to tell since you didn't tell what the error messages are, but I suspect that the 0x81 has something to do with them.

Share this post


Link to post
Share on other sites
You're not getting type mismatch errors are you? I dont know if this'll help, but heres some documentation for that function:

Syntax
istream& read(char*, int);
istream& read(signed char*, int);
istream& read(unsigned char*, int);

Description

The read member function extracts a given number of characters into an array. Use gcount() for the number of characters actually extracted if an error occurred.

Share this post


Link to post
Share on other sites
Starfall is 100% correct. What do you mean there is NO WAY to convert struct* to void* or char*...ALL pointers can be cast to ALL other pointers....it's just part of C....assuming your not in a system with near and far pointers

you just say this:
if( file.read((char*)&myStruct,sizeof(STRUCT)) != sizeof(STRUCT) )
// then you had an error

good luck

Share this post


Link to post
Share on other sites
Thanx for all your replies.
And the solution was JUST the thing that I haven't thought about. You see: the solution is in the place where you least expected.
I had tried things like:

char *ptr;
MYSTRUCT mstruct;

ptr=&mstruct

That wouldn't work. But type casting does work.

Share this post


Link to post
Share on other sites
You may also want to investigate
code:
reinterpret_cast (var_struct)

, as I've heard it provides a safer way to cast un-related types (in your case your struct type).

[This message has been edited by joeG (edited December 19, 1999).]

Share this post


Link to post
Share on other sites
When I try for example to read a structure from a file (method used by many) with fstream the compiler gives errors. I've typed this:

fstream file;
file.open("test.tst",0x81);
file.read(&struct,sizeof(struct));
file.close();

Many other C++ compilers doesn't seem to have problems with this, only borland's. Any way to solve this?

Share this post


Link to post
Share on other sites

This topic is 5077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.