Velocity Reviews > (type)*(var1)-like casting

# (type)*(var1)-like casting

grishin-mailing-lists@minselhoz.samara.ru
Guest
Posts: n/a

 03-16-2010
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)) >>
(((*((sizeof(Etype))))-((w)+1)*()) & ((1 << ()-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?
ANSWER: they aren't equal.
*/
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?

Seebs
Guest
Posts: n/a

 03-16-2010
On 2010-03-16, http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> 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 / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

grishin-mailing-lists@minselhoz.samara.ru
Guest
Posts: n/a

 03-16-2010
Indeed!

Thank you.

Keith Thompson
Guest
Posts: n/a

 03-16-2010
Seebs <(E-Mail Removed)> 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) (E-Mail Removed) <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"

Seebs
Guest
Posts: n/a

 03-16-2010
On 2010-03-16, Keith Thompson <(E-Mail Removed)> wrote:
> Seebs <(E-Mail Removed)> 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 / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

lawrence.jones@siemens.com
Guest
Posts: n/a

 03-16-2010
Seebs <(E-Mail Removed)> 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].
I doubt the OP would have had any trouble at all understanding it if it
had been written as (Etype)a[i] instead of (Etype)*(a + i).
--
Larry Jones

I wonder if I can grow fangs when my baby teeth fall out. -- Calvin

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Sosuke C++ 2 12-20-2009 03:24 PM Wally Barnes C++ 3 11-20-2008 05:33 AM Toby VHDL 3 09-07-2005 01:42 PM kevin Java 11 01-08-2005 07:11 PM Ben Nguyen VHDL 6 09-20-2003 05:09 PM

Advertisments