944,120 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 440
  • C RSS
Nov 3rd, 2009
0

32 bits/64 bits case

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jodie121997 is offline Offline
4 posts
since Oct 2009
Nov 3rd, 2009
-7
Re: 32 bits/64 bits case
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. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,961 posts
since Aug 2005
Nov 3rd, 2009
1
Re: 32 bits/64 bits case
  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
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Nov 3rd, 2009
0
Re: 32 bits/64 bits case
The purpose of these statement to cast the void point to either 32 or 64bits data type.
Thanks
J
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jodie121997 is offline Offline
4 posts
since Oct 2009
Nov 3rd, 2009
1
Re: 32 bits/64 bits case
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.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: UART problem!
Next Thread in C Forum Timeline: Print table of a number entered by user





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC