#Declaring Structs
2 messages in this thread
Thanks Don. I'll try that. I assume that the sizeof returns a correct size for
a given structure and one uses the structure labels to fill in the correct
values needed? If two structures have identical size, can one use one structure
as a different same sized structure if one fills the fields using the proper
labels? What I'm trying to ask is if the structures have a cast type? Thanks.
-Scott
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