| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Function args |
G'Day Paul,
-=> Quoting Paul Edwards to Frank Adam <=-
FA> Is it at all possible to send variable type and number of args to a
FA> function, and determine the types and number of them at runtime ?
PE> What are you really trying to do anyway? C++ has function
PE> overloading, if you want to go that route. BFN. Paul.
I was only killing time...
Basically, i was thinking of making up a generic function to assemble a
string. As i've said, vsprintf() will do a good job at it, but
it requires the format specifier.So i thought, what if...
int a = 10,b = 99,c = 109;
char ch1 = '+',ch2 = '=';
char *text = "The sum of";
printf("%s",func(text,a,ch1,b,ch2,c3,NULL);
and then func() would peel off the pointers one by one, and perform some
magic so it could find the length of and type of it, convert it to string
if necessary,cat it to retstr and then some more magic finding and fetching
the next one until it finds a NULL.
This came on while i was using Visual Basic last weekend, and there
you could have : mainstr = str1 + dec + long + str2 + single etc...all in
the same sentence.
You can, but it's not necessary to do a type conversion on any of those.
In C++ you can overload the + operator and do the same,but of course the
type conversion would then take place within those functions.
I don't think i'll find a way to do anything like this in C though.
It just bugs me that stupid Basic can do it and C can't :)
But i'm fast remembering why i gave up Basic.
eg: if(str = Null) True or False ? :)
L8r Frank (fadam{at}ozemail.com.au).
___ Blue Wave/DOS v2.21
--- Maximus 3.01
* Origin: The Software Parlour (3:635/544)SEEN-BY: 50/99 78/0 620/243 623/630 632/349 635/503 544 727 711/401 409 410 SEEN-BY: 711/413 430 808 809 932 934 712/515 713/888 714/906 800/1 7877/2809 @PATH: 635/544 50/99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.