Archived

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

Pointer structures in Borland C++

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

Recommended Posts

What are the errors that you are getting?

Share on other sites
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 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

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 on other sites
It gives the following error:
Can not find a match for

And there is just no way to convert the STRUCT* to a void* or char*.

Share on other sites
What happens if you use (char*)(&struct)? I don't see any reason why this wouldn't work, unless I'm missing something here...

Good luck

Starfall

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:
// then you had an error

good luck

Share on other sites
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.

char *ptr;
MYSTRUCT mstruct;

ptr=&mstruct

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

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 on other sites
char *ptr;
MYSTRUCT mstruct;

ptr=&mstruct;

This should also work, if you want to do it this way - just use:

ptr = (char*)&mstruct;

Regards

Starfall

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.close();

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

thats correct

Share on other sites

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

This topic is now closed to further replies.