[prog] Passing data between modules

Meredydd meredydd at everybuddy.com
Tue Jul 29 12:22:05 EST 2003


On Tuesday 29 July 2003 12:03, Dan Richter wrote:
> >Why is it more difficult to change the data structures in C?  As
> > opposed to in any language that has to serialize the communication
> > and have data structures?
>
> Good point. I had forgotten that in C, you don't even need to
> serialize: write(fd, &big_structure, sizeof(big_structure));

Well, you *can*...but you need to be very careful. If any of the members 
of that structure are pointers, then you're stuffed - you'll write the 
value of the pointer to the bytestream, and the other end will pull out 
a structure complete with pointers to thin air. The only way this 
method works is for *all* strings to be char[] arrays. This presents 
problems in that it wastes memory, is less flexible, etc, but it can be 
worth the hassle for the free not-quite-serialisation.

Meredydd



More information about the Programming mailing list