Functions

does anybody have a clue how to do a function which
return several variables ??

like:

main.c
int bla bla {

int a,b,c,d;
a,b,c,d = GetKey(a,b,c,d)

}

GetKey(int a, int b, int c, int d)
{

do_a_lot_of_funny_things;

return a,b,c,d;
}

thankz for your solutions - it’s great to have people like you - who
know what they are programming…

bye–
From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

Joachim Schiele wrote:

does anybody have a clue how to do a function which
return several variables ??

like:

main.c
int bla bla {

int a,b,c,d;
a,b,c,d = GetKey(a,b,c,d)

}

The way you’d do it would be

void GetKey(int a, int b, int c, int d, int *w, int *x, int *y, int z)
{
/
do random stuff, compute the “return values” */
*w = (first retval)
*x = (second retval)
*y = (third retval)
*z = (fourth retval)
}

and you’d call it this way:

int main(int argc, char *argv)
{
int a, b, c, d;
/
blah, blah, blah… */

GetKey(a, b, c, d, &a, &b, &c, &d);
}

You pass pointers to the function for the values you want returned.–
Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
ICSM-F Development Team +63 (917) 4458925
University of the Philippines Diliman

You could, of course, do this.

typedef struct { int a; int b; int c; int d;} myretval;

myretval myfunc()
{

myretval temp={foo,bar,gah,eek};
return temp;
}On Mon, Jun 26, 2000 at 01:40:03AM +0800, Dido Sevilla wrote:

Joachim Schiele wrote:

does anybody have a clue how to do a function which
return several variables ??

like:

main.c
int bla bla {

int a,b,c,d;
a,b,c,d = GetKey(a,b,c,d)

}

The way you’d do it would be

void GetKey(int a, int b, int c, int d, int *w, int *x, int *y, int z)
{
/
do random stuff, compute the “return values” */
*w = (first retval)
*x = (second retval)
*y = (third retval)
*z = (fourth retval)
}

and you’d call it this way:

int main(int argc, char *argv)
{
int a, b, c, d;
/
blah, blah, blah… */

GetKey(a, b, c, d, &a, &b, &c, &d);
}

You pass pointers to the function for the values you want returned.

“I know not with what weapons World War III will be fought, but I know
that World War IV will be four with sticks and stones.” — Einstein

Use a struct

typedef struct S {

``````int a, b, c, d;
};
``````

int main () {
S var;
var = function();On Sun, 25 Jun 2000, Joachim Schiele wrote:

does anybody have a clue how to do a function which
return several variables ??

like:

main.c
int bla bla {

int a,b,c,d;
a,b,c,d = GetKey(a,b,c,d)

}

GetKey(int a, int b, int c, int d)
{

do_a_lot_of_funny_things;

return a,b,c,d;
}

thankz for your solutions - it’s great to have people like you - who
know what they are programming…

bye

From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

THANKZ this was great !!!On Mon, 26 Jun 2000, you wrote:

Use a struct

typedef struct S {

int a, b, c, d;
};

int main () {
S var;
var = function();

On Sun, 25 Jun 2000, Joachim Schiele wrote:

does anybody have a clue how to do a function which
return several variables ??

like:

main.c
int bla bla {

int a,b,c,d;
a,b,c,d = GetKey(a,b,c,d)

}

GetKey(int a, int b, int c, int d)
{

do_a_lot_of_funny_things;

return a,b,c,d;
}

thankz for your solutions - it’s great to have people like you - who
know what they are programming…

bye

From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

well i would say that this is not the best way, better you should give
to the function the pointer to this struct, and in function access it
trough the pointer.

``````KovacsOn Mon, 26 Jun 2000, Joachim Schiele wrote:
``````

THANKZ this was great !!!

On Mon, 26 Jun 2000, you wrote:

Use a struct

typedef struct S {

``````int a, b, c, d;
};
``````

int main () {
S var;
var = function();

On Sun, 25 Jun 2000, Joachim Schiele wrote:

does anybody have a clue how to do a function which
return several variables ??

like:

main.c
int bla bla {

int a,b,c,d;
a,b,c,d = GetKey(a,b,c,d)

}

GetKey(int a, int b, int c, int d)
{

do_a_lot_of_funny_things;

return a,b,c,d;
}

thankz for your solutions - it’s great to have people like you - who
know what they are programming…

bye

From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

yes a pointer to the struct would be much better!On Mon, 26 Jun 2000, Kovacs wrote:

well i would say that this is not the best way, better you should give
to the function the pointer to this struct, and in function access it
trough the pointer.

Kovacs

On Mon, 26 Jun 2000, Joachim Schiele wrote:

THANKZ this was great !!!

On Mon, 26 Jun 2000, you wrote:

Use a struct

typedef struct S {

``````int a, b, c, d;
};
``````

int main () {
S var;
var = function();

On Sun, 25 Jun 2000, Joachim Schiele wrote:

does anybody have a clue how to do a function which
return several variables ??

like:

main.c
int bla bla {

int a,b,c,d;
a,b,c,d = GetKey(a,b,c,d)

}

GetKey(int a, int b, int c, int d)
{

do_a_lot_of_funny_things;

return a,b,c,d;
}

thankz for your solutions - it’s great to have people like you - who
know what they are programming…

bye

From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]