Article View: comp.lang.c.moderated
Article #2118Re: Variable param for non-vararg subr. calls
From: Jens M Andreasen
Date: Fri, 01 Mar 1996 15:30
Date: Fri, 01 Mar 1996 15:30
130 lines
3535 bytes
3535 bytes
he he he ..
I said it couldn't be done? Makes no sense? Maybe I was wrong ...
Here are some basic assumptions. Please compile and tell me if it runs,
and I shall complete the rest (the actual varargs call) as soon as possible.
I plan to make the call similar to printf, will that be OK?
// Jens M Andreasen
PS: I forgot to typedefine the stack (gcc was not so happy :)
mars>stack_test_1
- testing puts -------------------------
Format string! %s %.1f, %#x
- testing MyFun ------------------------
Format string! %s %.1f, %#x
The second string!
- testing printf -----------------------
Format string!
Hey, look at this!!
1.0, 0x32
- end of stacktest -
[mission impossible, part one]
/* stack_test_1.c ----------------------------------- */
#include <stdio.h>
#include <stdlib.h>
/* IMPORTANT_________________________
*
* Must be compiled with stack
* parameter calling conventions ON
*
* LC 5.06 may like to know that:
* Value for ___printf == _printf
*
* ----------------------------------
*
* 29/02/96 16:35 // Jens M Andreasen
*
*/
/* The unknown function carrying around its own stack */
struct frame{
char *arg;
char *string;
double one;
int two;
void(*F)(struct frame);
}*stack;
void MyFun(char* c,char* d){
static char *e = "\n Hey, look at this!!\n";
puts (c);
puts (d);
stack->string = e;
}
main(void){
float one = 1.00001;
char two = '2'; /* 0x32 */
stack = malloc(sizeof (struct frame));
/* collect some items .. */
stack->string = " The second string!\n";
stack->one = one;
stack->two = two;
/* and (somehow) keep track of them for printf() */
stack->arg = "\n Format string! %s %.1f, %#x\n";
/* Now the fun begins! We have a stack. There are
* lots of parameters on it. The functions that are
* called will pick their arguments from the top
* (ehrm), I mean _hopefully_ do so ... ;-)
*
*/
puts("- testing puts -------------------------");
stack->F = (void(*)(struct frame))puts;
stack->F(*stack);
puts("- testing MyFun ------------------------");
stack->F = (void(*)(struct frame))MyFun;
stack->F(*stack);
puts("- testing printf -----------------------");
stack->F = (void(*)(struct frame))printf;
stack->F(*stack);
puts("\n- end of stacktest -");
return 0 ;
/* return bug report to: jens-and@dsv.su.se */
}
Technical Details
Message-ID:
<4h7560$4gr@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: Jens M Andreasen <jens-and@dsv.su.se> Newsgroups: comp.lang.c.moderated Subject: Re: Variable param for non-vararg subr. calls Date: 1 Mar 1996 09:30:08 -0600 Organization: Digital Solutions Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4h7560$4gr@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com