arut
asked on
casting a pointer to unsigned int
I came across something like the foll:
packet_initialize ( (PACKET_HANDLE )p_pkt);
where typedef UINT PACKET_HANDLE;
and struct packet *p_pkt;
I wonder how a pointer to packet can be cast to an unsigned int
packet_initialize ( (PACKET_HANDLE )p_pkt);
where typedef UINT PACKET_HANDLE;
and struct packet *p_pkt;
I wonder how a pointer to packet can be cast to an unsigned int
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dear arut,
The basic concept of Pointers in C is hold a uint value which is expected to be a reference to the memory location.
if you declare a pointer like void *void_ptr; it can hold any type of pointer reference. but it should be handled like a hash key. the address of datum which u r storing in that should be referenced using the same type only.
int int_, *int_ptr;
FILE *fp1, *fp2;
void *void_;
void_ = &int_;
int_ptr = ( int *) void_;
void_ = fp1;
.............
..................
fp2 = ( FILE *)void_;
like that. in one line to say you can play withe uint value with the pointer to reference. provided dereferencing should be casted to get the exact result. Hope this gives a solution . all the best
-regards
pkarth
The basic concept of Pointers in C is hold a uint value which is expected to be a reference to the memory location.
if you declare a pointer like void *void_ptr; it can hold any type of pointer reference. but it should be handled like a hash key. the address of datum which u r storing in that should be referenced using the same type only.
int int_, *int_ptr;
FILE *fp1, *fp2;
void *void_;
void_ = &int_;
int_ptr = ( int *) void_;
void_ = fp1;
.............
..................
fp2 = ( FILE *)void_;
like that. in one line to say you can play withe uint value with the pointer to reference. provided dereferencing should be casted to get the exact result. Hope this gives a solution . all the best
-regards
pkarth
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If this machine has UINT type big enough to hold a pointer, this cast will probably "work". A better question to ask is why the called function expects a UINT when a pointer to a packet would make a heck of a lot more sense. There may be some not very good historical or arbitrary design decision lurking in there. It wouldnt hurt to look into that aspect. Maybe you can get the design changed.
compiler just needs to be sure that you know what you are doing