Passing sizes of arrays without a separate argument for the length
Dave Jones
djones at megatest.UUCP
Wed Sep 21 12:41:32 AEST 1988
In article <8809191507.AA17512 at ucbvax.Berkeley.EDU> U23405 at UICVM (Michael J. Steiner) writes:
)BEFORE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
)main()
){
) char array[10];
) ...
) somefunc(array,10);
)}
)
)AFTER (MY IDEA) : - - - - - - - - - - - - - - - - - - - - - - - - - - - -
)main()
){
) char array[10];
) ...
) array[0] = 10;
) somefunc(array);
)}
)
Try this:
typedef struct
{
int size;
char* contents;
}Var_array;
main()
{
char contents[10];
Var_array array;
array.size = sizeof(contents);
array.contents = contents;
somefunc(array);
}
/* Works good. Lasts a long time. */
More information about the Comp.lang.c
mailing list