Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,618 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Variable Arguments #158489
10/03/07 16:02
10/03/07 16:02
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline OP

Serious User
TWO  Offline OP

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
JCL once postet a piece of code from a standard C book. With some fiddling I erased all compiler errors, but it produces a crash. So, any chance to get some variable args into my app?

Re: Variable Arguments [Re: TWO] #158490
10/06/07 16:11
10/06/07 16:11
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline OP

Serious User
TWO  Offline OP

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
Boo is making some Foo.

Re: Variable Arguments [Re: TWO] #158491
10/07/07 09:22
10/07/07 09:22
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline OP

Serious User
TWO  Offline OP

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
bump bump bump

Re: Variable Arguments [Re: TWO] #158492
10/07/07 10:17
10/07/07 10:17
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Are you talking about

int main(int argc, char *argv[])

or

void func(int, ...);

Re: Variable Arguments [Re: Excessus] #158493
10/07/07 10:22
10/07/07 10:22
Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
TripleX Offline
Expert
TripleX  Offline
Expert

Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
example for variable arguments:

Code:

#include <cstdarg>
#include <iostream>

using namespace std;

double average ( int num, ... )
{
va_list arguments; // A place to store the list of arguments
double sum = 0;

va_start ( arguments, num ); // Initializing arguments to store all values after num
for ( int x = 0; x < num; x++ ) // Loop until all numbers are added
sum += va_arg ( arguments, double ); // Adds the next value in argument list to sum.
va_end ( arguments ); // Cleans up the list

return sum / num; // Returns some number (typecast prevents truncation)
}
int main()
{
cout<< average ( 3, 12.2, 22.3, 4.5 ) <<endl;
cout<< average ( 5, 3.3, 2.2, 1.1, 5.5, 3.3 ) <<endl;
}



Re: Variable Arguments [Re: TripleX] #158494
10/07/07 11:14
10/07/07 11:14
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline OP

Serious User
TWO  Offline OP

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
As I'm skilled in Cpp I know how to use them there I want a Lite-C sample cause I never got it to work there.

Referring to this thread: http://www.coniserver.net/ubbthreads/sho...true#Post733811

Re: Variable Arguments [Re: TWO] #158495
10/07/07 14:23
10/07/07 14:23
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
Seems like it simply doesn't work. The arguments aren't copied to the stack in case of "...".

I wrote a little program that demonstrates it. Both functions tst1 and tst2 should return the integer that is stored after parameter a. This seems to work only for tst1.

Code:

#include <acknex.h>
int tst1(int a, int b)
{
return *((&a) + 1);
}
int tst2(int a, ...)
{
return *((&a) + 1);
}

int main()
{
if(tst1(1, 2) == 2)
printf("test 1 success");
else
printf("test 1 failure");

if(tst2(1, 2) == 2)
printf("test 2 success");
else
printf("test 2 failure");
}



Re: Variable Arguments [Re: Excessus] #158496
10/08/07 23:05
10/08/07 23:05
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

Was int not changed to integer?

Ottawa

Re: Variable Arguments [Re: Ottawa] #158497
10/08/07 23:56
10/08/07 23:56
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
JCL stated, that this is not supported at the moment, because it required major changes in the way the compiler works. However, he stated he'd take care about this in the future.


Always learn from history, to be sure you make the same mistakes again...

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1