arrays and structures in C

Freedman jfjr at mitre-bedford.arpa
Fri Apr 15 23:19:13 AEST 1988


  I've asked similar questions so if this sound familiar please
bear with me.

 Suppose I have some (rather large) type and I want to
dynamically allocate a (rather large) array of said type.
The natural way to do this is sort like this

malloc(some_large_integer*(sizeof(rather_large_type))).

But given some well known architectures this ties the
compiler hands - it must allocate contiguous storage.

Alternatively you could declare  

typedef rather_large_type large_array[some_large_integer];

but I haven't had much luck with malloc(sizeof(large_array))

Now I can do this

typedef struct {
          int dummy_field;
          large_array large;
          } large_structure;

malloc(sizeof(large_structure)) 

this seems to work and looks more portable than anything else but
its not pretty. Have I missed something??

                                          signed
                                          Continuously Confused


Jerry Freedman, Jr      "Love is staying up all night 
jfjr at mitre-bedford.arpa   with a sick child,
(617)271-4563            or a healthy adult"



More information about the Comp.lang.c mailing list