32 bits/64 bits case

Reply

Join Date: Oct 2009
Posts: 3
Reputation: jodie121997 is an unknown quantity at this point 
Solved Threads: 0
jodie121997 jodie121997 is offline Offline
Newbie Poster

32 bits/64 bits case

 
0
  #1
21 Days Ago
Hi All,
I have the application which will be support 32 bits and 64 bits
and below are the statement to handle 32bits/64bits data
and new_node->data
is void * new_node->data
for ( index = 0 ; index < items ;index++ ) {
if (data_size == SIZE_32 ) {
* ( ((int32_t*)(new_node->data)) + index) = (int32_t) index*2 ;
* ( ((int32_t*)(new_node-> data)) + index) = (int32_t) index*3
}
else {
* ( ((int64_t*)(new_node-> data)) + index) = (int64_t) index*4;
* ( ((int64_t*)(new_node-> data)) + index) = (int64_t) index*5;
}
}
Is there any better to handle this without the if/else statement (if ((data_size == SIZE_32 ) {
Thanks
J
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,342
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-5
  #2
21 Days Ago
I would use a typedef

  1. #ifdef SIZE_32
  2. typedef __int32 inttype;
  3. #else
  4. typedef __int64 inttype;
  5. #endif
  6.  
  7. int main()
  8. {
  9. inttype a = 0;
  10. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,030
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 176
Aia's Avatar
Aia Aia is offline Offline
Postaholic
 
1
  #3
21 Days Ago
  if (data_size == SIZE_32 ) {
      * ( ((int32_t*)(new_node->data)) + index) = (int32_t) index*2 ; 
      * ( ((int32_t*)(new_node-> data)) + index) = (int32_t) index*3;
    }
   else {
       * ( ((int64_t*)(new_node-> data)) + index) = (int64_t) index*4; 
      * ( ((int64_t*)(new_node-> data)) + index) = (int64_t) index*5;
}
What's the purpose of this assignment :
* ( ((int32_t*)(new_node->data)) + index) = (int32_t) index*2 ; if in the next expression it gets changed right away?
* ( ((int32_t*)(new_node-> data)) + index) = (int32_t) index*3; Same in the else
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: jodie121997 is an unknown quantity at this point 
Solved Threads: 0
jodie121997 jodie121997 is offline Offline
Newbie Poster
 
0
  #4
21 Days Ago
The purpose of these statement to cast the void point to either 32 or 64bits data type.
Thanks
J
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,030
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 176
Aia's Avatar
Aia Aia is offline Offline
Postaholic
 
1
  #5
21 Days Ago
Originally Posted by jodie121997 View Post
The purpose of these statement to cast the void point to either 32 or 64bits data type.
Thanks
J
It was intended to be a hint, rather that a question to answer.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC