Solved

Casting question

Posted on 2002-03-27
5
259 Views
Last Modified: 2010-04-15
This question is about casting and
leading *:s

Does
  a_p = ***(void****)b_p
make sence ?
Is it the same as
  a_p = *(void****)b_p ???

/Confused
0
Comment
Question by:CrypToniC
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6899279
>>Does
>> a_p = ***(void****)b_p
>>make sence ?

Yes, absolutely. I mean, if 'b_p' is of type 'void****', of course,

>Is it the same as
> a_p = *(void****)b_p ???

No, not at all - this makes 'a_p' an 'void***'
0
 
LVL 5

Expert Comment

by:BlackDiamond
ID: 6899859
CryptToniC,
jkr is absolutely correct.   I will elaborate a couple more examples that should hopefully make the derefrencing more clear.

void a_p = ****(void****)b_p
void * a_p = ***(void****)b_p
void ** a_p = **(void****)b_p
void *** a_p = *(void****)b_p
void **** a_p = (void****)b_p



0
 
LVL 5

Expert Comment

by:BlackDiamond
ID: 6899881
also, I only included the first line for clarity.  It is actually illegal to have a (void) variable (since it would have no context of size).  The way you would use the first line would be more like:

int a_p = (int)(****(void****)b_p)
0
 

Expert Comment

by:0xDEADBEEF
ID: 6902088
Hmmm... a void**** variable would indicate a 3d-array of pointers to void, so

void* a_p = ***(void****)b_p

would be the same as

void* a_p = b_p[0][0][0];

so a_p is a pointer to void, or, the contents of a slot.  But

void*** a_p = *(void***)b_p;

would equal

void*** a_p = b_p[0];

so a_p would be a pointer to a pointer to a pointer to void, or, a 2d-array of pointers to void.

Hope this helps, I know it's confusing.
0
 
LVL 1

Author Comment

by:CrypToniC
ID: 6912223
jkr, was the first to answer so this seems fair

Hmm if one returns to basics the answer is often obvious :)

Not often I see code like this, Thanks alot
Regards CrypToniC
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 167
Details to do the search 56 142
Grammars for C C++ and java 1 108
Unable to start eclipse ? 17 83
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now