Connecting Tech Pros Worldwide Forums | Help | Site Map

det_Z(A).r instead of z.r

xhungab
Guest
 
Posts: n/a
#1: Sep 3 '06
Hello,

If the function det_Z(), is of this type :

complexZ det_Z(double **A);

Can I write :

do
{
r_mZ(A,999.);
printf(".");
}while(!det_Z(A).r);


instead of

complexZ z;

do
{
r_mZ(A,999.);
z = det_Z(A);
printf(".");
}while(!z.r);

Thank

http://groups.yahoo.com/group/mathc/


Richard Bos
Guest
 
Posts: n/a
#2: Sep 4 '06

re: det_Z(A).r instead of z.r


"xhungab" <xhungab@yahoo.frwrote:
Quote:
If the function det_Z(), is of this type :
>
complexZ det_Z(double **A);
>
Can I write :
>
do
{
r_mZ(A,999.);
printf(".");
}while(!det_Z(A).r);
>
instead of
>
complexZ z;
>
do
{
r_mZ(A,999.);
z = det_Z(A);
printf(".");
}while(!z.r);
Sure, provided a complexZ has a member called r which is a scalar - but
if it didn't, your second snippet wouldn't work, either.

Richard
Simon Biber
Guest
 
Posts: n/a
#3: Sep 5 '06

re: det_Z(A).r instead of z.r


xhungab wrote:
Quote:
Hello,
>
If the function det_Z(), is of this type :
>
complexZ det_Z(double **A);
You haven't completely specified the type, since you haven't told us
what a complexZ is. But it is clear that det_Z is a function that takes
a pointer to pointer to double, and returns a complexZ. Whatever that is.

You also haven't told us what this function is supposed to do.
Quote:
Can I write :
>
do
{
r_mZ(A,999.);
printf(".");
}while(!det_Z(A).r);
How are we to know, without the declaration of r_mZ, A, and complexZ?

You haven't told us what type A is. It should be a pointer to pointer to
double, or perhaps pointer to void, if the above code is correct.

You haven't told us what type complexZ is. It should be a struct
containing at least one member, named r, of an arithmetic or pointer type.

You haven't told us what the type of r_mZ is. It should be a function
taking two arguments: (1) a pointer to pointer to double and (2) a
double. It should probably return void, but it may return something else
if you ignored its return value above.
Quote:
instead of
>
complexZ z;
>
do
{
r_mZ(A,999.);
z = det_Z(A);
printf(".");
}while(!z.r);
The code above is equivalent to the previous code. The exception is that
the value of z is still available after the loop in case you still
wanted to use it.

I suppose the question should have been:

"Can I use the struct member access operator (.) directly
on the return value of a function?"

struct foo {int a;};

struct foo bar(void)
{
return (struct foo){0};
}

int main(void)
{
return bar().a;
}

The answer is, yes, you can.

--
Simon.
xhungab
Guest
 
Posts: n/a
#4: Sep 5 '06

re: det_Z(A).r instead of z.r


You are right.
Quote:
>I suppose the question should have been:
>
"Can I use the struct member access operator (.) directly
on the return value of a function?"
Thank for your answer.

Ps:

typedef struct
{
double r;
double i;
} complexZ,
*pcomplexZ;

It is a pointer on a complex matrix.
I have try to follow the indication given
into the group "comp.lang.c"
But I have customized the method.
double **A;

r for rand.
void r_mZ(double **A, int n);

det for determinant.
complexZ det_Z(double **A);

Closed Thread