CompuServe Messages

Declaring Structs

    01-Feb-89 02:10:34
Fm: Don Curtis/SYSOP 76703,4321
To: Scott Ainbinder 71600,3472
Scott, No…you can't cast structure of type a to a structure of type b. No…you can't assume that structures that you think are the same size will take up the same amount of room in memory, byte alignment can cause size differences. Yes, the sizeof function will return the amount of memory that the structure needs, you fill it out via pointer ops: eg. struct MyText { int size; char text[40]; struct MyText *next; }; struct MyText *first_line, *second_line; extern void *malloc(); first_line = (struct MyText *) malloc((long)sizeof(struct MyText)); first_line->size = 0; first_line->text[0] = '\0'; second_line = (struct MyText *) malloc((long)sizeof(struct MyText)); first_line->next = second_line; You can of course, substitute the Amiga function AllocRemember for the malloc() call. Don