Confirmation on C problem

AgentEL

Golden Member
Jun 25, 2001
1,327
0
0
I just want to confirm something with someone:

some_ptr = (char *) (void *) diff_ptr;

This line will cast diff_ptr to a void*, then to char*, right?

Weird thing to do, I know. But please humor me.
 

BFG10K

Lifer
Aug 14, 2000
22,709
3,007
126
I believe so. If you're not sure use () to force the order you want.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
1 + 2 + 3

is equivelant to

1 + (2 + (3 + 4))

so your statement, I believe, would be equivelant to

some_ptr = (char *) ((void *) diff_ptr);

so yeah, it should do what you want.
 

arcain

Senior member
Oct 9, 1999
932
0
0
Originally posted by: BingBongWongFooey
1 + 2 + 3

is equivelant to

1 + (2 + (3 + 4))

so your statement, I believe, would be equivelant to

some_ptr = (char *) ((void *) diff_ptr);

so yeah, it should do what you want.

That is a poor example. Though equivalent in a mathematical sense, the addition (+) operator is left associative.
So 1 + 2 + 3 + 4 (I assume you intended to put a 4 there) is really (((1+2) + 3) + 4).

A C style cast is right associative, and your last statement is correct.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
:(

I thought all of the operators worked left to right. Or right to left.. or whatever. I was thinking of << and figured that + was the same. And yeah, I meant to have a 4 there. ;)
 

Replicon

Member
Apr 23, 2002
152
0
71
Sorry but i have to ask, out of curiosity - what ARE you doing that requires that cast? Is it just a homework question?