Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 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 | chip programmers | 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