Path: utzoo!attcan!uunet!ingr!crossgl From: crossgl@ingr.UUCP (Gordon Cross) Newsgroups: comp.lang.c Subject: Re: Re: variable number of strings passed t Summary: using malloc as an argument passing mechanism is NOT recommended Message-ID: <2774@ingr.UUCP> Date: 31 Oct 88 17:08:30 GMT References: <434@tutor.UUCP> <225800083@uxe.cso.uiuc.edu> Organization: Intergraph Corp. Huntsville, Al Lines: 37 In article <225800083@uxe.cso.uiuc.edu>, mcdonald@uxe.cso.uiuc.edu writes: > Oh come on now. How about mallocing up enough space to put an array > of pointers to the strings in memory and passing a pointer to that array? > That is portable and avoids varargs or stdarg. Yes this is true: portability is maintained and you avoid the (messy??) varargs convention. However, I would NOT recommend using malloc in this fashion for two reasons: 1) First, mallocing memory is usually a costly (timewise) undertaking when compared to the time it takes to pass arguments. Most decent compilers should pass arguments using the most efficient method possible. If you are calling such a function many times, you may find yourself spending all of your time mallocing and freeing! 2) Your code would be "messy" (descriptive term) in the areas where you call this function because you would have to do this: buffer = (char **)malloc (size); buffer[0] = "arg1"; buffer[1] = "arg2"; . . . buffer[n] = 0; yourfunction (buffer); free (buffer); If you have to do this in very many different places, your code size could adversely affected. Wouldn't it be much nicer to be able to call the function with the single line yourfunction ("arg1", "arg2", ... , 0); Gordon Cross Intergraph Corp. Huntsville, AL