🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2136

Re: Varaible param for non-vararg subr. calls

#2136
From: Aubrey K. Knight
Date: Fri, 01 Mar 1996 15:36
44 lines
1904 bytes
One possible scenario


      You know all of the functions that will be called and
      all of their argument lists, but they may change from
      version to version.

      Ok, to solve this problem you define the following:

	1. A structure that defines the function name, the function
           to be called, the number of args, and their types.
       
        2. You define a search for an array of the above structure.

        3. You define a routine that given a function name, and
           either a va_list  or an argc, argv setup performs the 
           appropriate conversions and calls the function indicated.

      An example of this:
	In this example all of the functions have the same
        basic call structure.  
        This should be considered pseudocode.

        struct keys {
          char *k_wd;
	  int (*k_ptr)();
        } keybuff = {{"Special", Special}, {"test", test}, 
		     {NULL, NULL}};

	int (*Exec(command))()
		char *command;
	{
	     struct keys *kp;
	     for (kp=keybuff; kp->k_wd; kp++)
		if (strcmp(kp->k_wd, command) == SAME)
			return (kp->k_ptr);
	     return (keybuff[0].k_ptr);
        }

            Example call Exec("test")(ac,av);

I suggest that you place the keybuff structure in a C file or library 
by itself.  Then all that is required is a recompile and relink of a
few new files instead of a rewrite of your function handling code.
Technical Details
Message-ID: <4h75hj$4s8@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: "Aubrey K. Knight" <knight@erc.msstate.edu>
Newsgroups: comp.lang.c.moderated
Subject: Re: Varaible param for non-vararg subr. calls
Date: 1 Mar 1996 09:36:19 -0600
Organization: Mississippi State University
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4h75hj$4s8@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3_U1 sun4c)