🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc.programmer
Article #240

Re: The Super strcat routine for lists ?? (HELP)

#240
From: John Eras
Date: Thu, 05 Apr 1990 18:54
35 lines
2489 bytes
In article <2619805E.18916@maccs.dcss.mcmaster.ca> cs4g6ag@maccs.dcss.mcmaster.ca (Stephen M. Dunn) writes:
>In article <1577@dinl.mmc.UUCP> noren@dinl.UUCP (Charles Noren) writes:
>$Try using a variable argument list.  The approach
>$in Turbo C (as in MSC and other ANSI C compilers)
>$is to use the va_... functions (check for "va_..."
>$in the Turbo C Reference Guide).  The trick with
>$these functions is being able to tell when you reached
>$the end of the arguments.  In the sample code below
>$the end of the argument list to the function must have
>$NULL as the last argument.
>
>   There must be a way of doing this that doesn't require you to put
>a NULL as the last argument ... after all, functions like printf ()
>take variable-size argument lists and you don't have to say
>
>   printf ("%d%s\n", integervar, stringvar, NULL);

That's because printf() et al. doesn't give a damn what you put on the stack
as arguments, because it derives the arguments that it needs and their sizes
from the format string that you pass in.  So you could do:
    printf("%d%s\n");
and printf() wouldn't care--it would simply pull garbage off the stack.
Similarly, you could do:
    printf("%d%s\n", 20_gazillion_worthless_arguments);
and printf() would only pull the appropriate number of arguments off the
stack and ignore the rest.

As far as the original question (not included above) goes, the answers to
this problem are pretty trivial, and involve using one of the [s]printf()
family or using a null-terminated list of strings passed to a routine
with a strcat() loop.  Which one you use is a matter of personal preference.
--
AT:    jeras@oracle.com                              | "It's a terrible waste
BANG:  ...{pacbell,hplabs,apple,decwrl}!oracle!jeras | to lose one's .sig, or
FLAME: /dev/null                                     | not to have one at all."
Technical Details
Message-ID: <1990Apr5.185454.27071@oracle.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!apple!oracle!news
References: <1990Apr3.023410.6401@cunixf.cc.columbia.edu> <1577@dinl.mmc.UUCP> <2619805E.18916@maccs.dcss.mcmaster.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!apple!oracle!news
From: jeras@oracle.oracle.com (John Eras)
Newsgroups: comp.sys.ibm.pc.programmer
Subject: Re: The Super strcat routine for lists ?? (HELP)
Keywords: strcat, lists
Message-ID: <1990Apr5.185454.27071@oracle.com>
Date: 5 Apr 90 18:54:54 GMT
References: <1990Apr3.023410.6401@cunixf.cc.columbia.edu> <1577@dinl.mmc.UUCP> <2619805E.18916@maccs.dcss.mcmaster.ca>
Reply-To: jeras@oracle.com (John Eras)
Organization: Oracle Corporation, Belmont, CA
Lines: 35