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

I would use a typedef

#ifdef SIZE_32
   typedef __int32 inttype;
#else
   typedef __int64 inttype;
#endif

int main()
{
    inttype a = 0;
}
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

The purpose of these statement to cast the void point to either 32 or 64bits data type.
Thanks
J

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.