Changeset 21035

Show
Ignore:
Timestamp:
02/23/08 07:21:55 (9 months ago)
Author:
patrick
Message:

Dramatically improved the readability of Ntohll() and Htonll() by using C++
casting instead of C-style casting and by removing unneeded parentheses.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vapor/vpr/md/NSPR/SystemNSPR.h

    r20974 r21035  
    4646#include <vpr/vprConfig.h> 
    4747 
    48 #include <stdlib.h> 
    49 #include <string.h> 
     48#include <cstdlib> 
    5049#include <string> 
    5150#include <prtime.h> 
     
    139138   { 
    140139      vpr::Uint64 ret_val; 
    141       if (isLittleEndian()) 
    142       { 
    143          *((vpr::Uint32*)(&ret_val) + 1) = SystemNSPR::Ntohl(*((vpr::Uint32*)(&conversion))); 
    144          *( ((vpr::Uint32*)(&ret_val))) = SystemNSPR::Ntohl( *( ((vpr::Uint32*)(&conversion))+1) ); 
     140 
     141      if ( isLittleEndian() ) 
     142      { 
     143         *(reinterpret_cast<vpr::Uint32*>(&ret_val) + 1) = 
     144            Ntohl(*reinterpret_cast<vpr::Uint32*>(&conversion)); 
     145         *reinterpret_cast<vpr::Uint32*>(&ret_val) = 
     146            Ntohl(*(reinterpret_cast<vpr::Uint32*>(&conversion) + 1)); 
    145147      } 
    146148      else 
    147149      { 
    148          *((vpr::Uint32*)(&ret_val)) = SystemNSPR::Ntohl(*((vpr::Uint32*)(&conversion))); 
    149          *( ((vpr::Uint32*)(&ret_val)) + 1) = SystemNSPR::Ntohl( *( ((vpr::Uint32*)(&conversion))+1) ); 
    150       } 
     150         *reinterpret_cast<vpr::Uint32*>(&ret_val) = 
     151            Ntohl(*reinterpret_cast<vpr::Uint32*>(&conversion)); 
     152         *(reinterpret_cast<vpr::Uint32*>(&ret_val) + 1)  = 
     153            Ntohl(*(reinterpret_cast<vpr::Uint32*>(&conversion) + 1)); 
     154      } 
     155 
    151156      return ret_val; 
    152157   } 
     
    183188   { 
    184189      vpr::Uint64 ret_val; 
    185       if (isLittleEndian()) 
    186       { 
    187          *((vpr::Uint32*)(&ret_val) + 1) = SystemNSPR::Htonl(*((vpr::Uint32*)(&conversion))); 
    188          *( ((vpr::Uint32*)(&ret_val))) = SystemNSPR::Htonl( *( ((vpr::Uint32*)(&conversion))+1) ); 
     190 
     191      if ( isLittleEndian() ) 
     192      { 
     193         *(reinterpret_cast<vpr::Uint32*>(&ret_val) + 1) = 
     194            Htonl(*reinterpret_cast<vpr::Uint32*>(&conversion)); 
     195         *reinterpret_cast<vpr::Uint32*>(&ret_val) = 
     196            Htonl(*(reinterpret_cast<vpr::Uint32*>(&conversion) + 1)); 
    189197      } 
    190198      else 
    191199      { 
    192          *((vpr::Uint32*)(&ret_val)) = SystemNSPR::Htonl(*((vpr::Uint32*)(&conversion))); 
    193          *( ((vpr::Uint32*)(&ret_val)) + 1) = SystemNSPR::Htonl( *( ((vpr::Uint32*)(&conversion))+1) ); 
    194       } 
     200         *reinterpret_cast<vpr::Uint32*>(&ret_val) = 
     201            Htonl(*reinterpret_cast<vpr::Uint32*>(&conversion)); 
     202         *(reinterpret_cast<vpr::Uint32*>(&ret_val) + 1) = 
     203            Htonl(*(reinterpret_cast<vpr::Uint32*>(&conversion) + 1)); 
     204      } 
     205 
    195206      return ret_val; 
    196207   } 
  • juggler/trunk/modules/vapor/vpr/md/POSIX/SystemPosix.cpp

    r20974 r21035  
    7272{ 
    7373   vpr::Uint64 ret_val; 
    74     
    75    if (isLittleEndian()
     74 
     75   if ( isLittleEndian()
    7676   { 
    77       *((vpr::Uint32*)(&ret_val) + 1) = SystemPosix::Ntohl(*((vpr::Uint32*)(&conversion))); 
    78       *( ((vpr::Uint32*)(&ret_val))) = SystemPosix::Ntohl( *( ((vpr::Uint32*)(&conversion))+1) ); 
     77      *(reinterpret_cast<vpr::Uint32*>(&ret_val) + 1) = 
     78         Ntohl(*reinterpret_cast<vpr::Uint32*>(&conversion)); 
     79      *reinterpret_cast<vpr::Uint32*>(&ret_val) = 
     80         Ntohl(*(reinterpret_cast<vpr::Uint32*>(&conversion) + 1)); 
    7981   } 
    8082   else 
    8183   { 
    82       *((vpr::Uint32*)(&ret_val)) = SystemPosix::Ntohl(*((vpr::Uint32*)(&conversion))); 
    83       *( ((vpr::Uint32*)(&ret_val)) + 1) = SystemPosix::Ntohl( *( ((vpr::Uint32*)(&conversion))+1) ); 
     84      *reinterpret_cast<vpr::Uint32*>(&ret_val) = 
     85         Ntohl(*reinterpret_cast<vpr::Uint32*>(&conversion)); 
     86      *(reinterpret_cast<vpr::Uint32*>(&ret_val) + 1)  = 
     87         Ntohl(*(reinterpret_cast<vpr::Uint32*>(&conversion) + 1)); 
    8488   } 
     89 
    8590   return ret_val; 
    8691} 
     
    8994{ 
    9095   vpr::Uint64 ret_val; 
    91    if (isLittleEndian()) 
     96 
     97   if ( isLittleEndian() ) 
    9298   { 
    93       *((vpr::Uint32*)(&ret_val) + 1) = SystemPosix::Htonl(*((vpr::Uint32*)(&conversion))); 
    94       *( ((vpr::Uint32*)(&ret_val))) = SystemPosix::Htonl( *( ((vpr::Uint32*)(&conversion))+1) ); 
     99      *(reinterpret_cast<vpr::Uint32*>(&ret_val) + 1) = 
     100         Htonl(*reinterpret_cast<vpr::Uint32*>(&conversion)); 
     101      *reinterpret_cast<vpr::Uint32*>(&ret_val) = 
     102         Htonl(*(reinterpret_cast<vpr::Uint32*>(&conversion) + 1)); 
    95103   } 
    96104   else 
    97105   { 
    98       *((vpr::Uint32*)(&ret_val)) = SystemPosix::Htonl(*((vpr::Uint32*)(&conversion))); 
    99       *( ((vpr::Uint32*)(&ret_val)) + 1) = SystemPosix::Htonl( *( ((vpr::Uint32*)(&conversion))+1) ); 
     106      *reinterpret_cast<vpr::Uint32*>(&ret_val) = 
     107         Htonl(*reinterpret_cast<vpr::Uint32*>(&conversion)); 
     108      *(reinterpret_cast<vpr::Uint32*>(&ret_val) + 1) = 
     109         Htonl(*(reinterpret_cast<vpr::Uint32*>(&conversion) + 1)); 
    100110   } 
     111 
    101112   return ret_val; 
    102113}