# (type)*(var1)-like casting

Discussion in 'C Programming' started by grishin-mailing-lists@minselhoz.samara.ru, Mar 16, 2010.

1. ### Guest

Hi there,

Dann Corbit's coding encouraged me to dig deeper into it.
I preprocessed something and found this

typedef signed int Etype;
count[((((Etype)*(a + i)-(Etype)(-2147483647 -1)) >>
(((8)*((sizeof(Etype))))-((w)+1)*(8))) & ((1 << (8))-1)) + 1]++; (1)

It's a part of radix most significant digit sort
which I've been trying to understand.

Well, variable a is known as Etype*, allright.
Part of statement (1):
( (Etype)*(a + i) - (Etype) (-2147483647 -1) )

this is usual casting
(Etype) (-2147483647 -1)

but what is that
(Etype)*(a + i) ?

I thought it was a peculiarities of preprocessing and wrote a program
to test this:

#include <stdio.h>

int main(void)
{
/*TASK: to find out is it possible to implement casting like
(type *) var

this way
(type)*(var)

Is that correct syntax?
*/
int i;
int *p;
int z = 1;

p = &i;
z = (int)*(p);

printf("%p\n", p);
printf("%d\n", z);

z = (int)p;
printf("%d\n", z);

return 0;
}

I:\prj\_Unleashed_C\ch13>a
0022FF54
0
2293588

They are different!
Well, what is (Etype)*(a + i) for?

, Mar 16, 2010

2. ### SeebsGuest

On 2010-03-16, <> wrote:
> but what is that
> (Etype)*(a + i) ?

The same thing as any other
(type) expression
would be. It's a cast of <expression> to <type>.

So we obtain the value "*(a + i)" and convert that value to an
Etype.

> They are different!
> Well, what is (Etype)*(a + i) for?

You're getting confused because you're expecting it to be in some way
special, because of the odd visual similarity between the things on each
side of the *, and you're forgetting that * is a perfectly ordinary
unary operator. "*p" is "contents of pointer p". If a is a pointer,
and i is an integer, then "a+i" is a pointer, and "*(a+i)" is the contents
of that pointer.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach /
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Seebs, Mar 16, 2010

3. ### Guest

Indeed!

Thank you.

, Mar 16, 2010
4. ### Keith ThompsonGuest

Seebs <> writes:
[...]
> "*p" is "contents of pointer p".

[...]

For sufficiently odd meanings of the word "contents".

*p is the object that p points to.

--
Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson, Mar 16, 2010
5. ### SeebsGuest

On 2010-03-16, Keith Thompson <> wrote:
> Seebs <> writes:
> [...]
>> "*p" is "contents of pointer p".

> [...]

> For sufficiently odd meanings of the word "contents".

> *p is the object that p points to.

Yeah. That's what I was trying to say, but yours has the very slight
advantage of being clearly correct rather than at best very confusing, or
possibly totally wrong.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach /
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Seebs, Mar 16, 2010
6. ### Guest

Seebs <> wrote:
>
> If a is a pointer,
> and i is an integer, then "a+i" is a pointer, and "*(a+i)" is the contents
> of that pointer.

It's worth pointing out that it's also a convoluted way of writing a.
I doubt the OP would have had any trouble at all understanding it if it