• Advertisement

Archived

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

concerning void*

This topic is 5369 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

Advertisement
You can''t. Without any way to tell what the variable is pointing to, there''s no possible way to correctly serialize the data.

What, exactly, are you trying to do?


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
i want to create a struct

struct data
{
void * pData;
char namevar[10];
};



on the program i decide what format i want to save on disk like int, char or float. then i want void to piont at it and save te struct on disk.

Share this post


Link to post
Share on other sites

struct blarg
{
void *ptr;
int size;
}

blarg b;
FILE *f = fopen("blarg.dat", "wb");
fwrite(b.ptr, b.size, 1, f);


[edited by - Nypyren on August 11, 2003 10:43:00 PM]

Share this post


Link to post
Share on other sites
Will it work if I say;


struct blarg
{
void *ptr;
char name[10]; // name of the variable as you declare them on acces

};

char *name = "Hello";

blarg b;
FILE *f = fopen("blarg.dat", "wb");
ptr = (char *)pname;
fwrite(b.ptr, b.size, 1, f);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How about this:

struct blarg
{
void *ptr;
int size;
char name[10]; // name of the variable as you declare them on acces
};

char *name = "Hello";
blarg b;
FILE *f = fopen("blarg.dat", "wb";

b.ptr=pname;
char *data=(char *)b.ptr;

fwrite(data, b.size, 1, f);

Share this post


Link to post
Share on other sites
You still have to establish the struct''s real size when loading it.
It''s only convenient that the size is stored in, preferably the beginning of, the struct.
Reason for beginning of struct?
You can read it from file first, before loading the rest...

Share this post


Link to post
Share on other sites

  • Advertisement