Browse Source

[2009] Add comment about why a static_cast is necessary

Mukund Sivaraman 13 years ago
parent
commit
afc0fe7345
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/lib/xfr/xfrout_client.cc

+ 6 - 1
src/lib/xfr/xfrout_client.cc

@@ -82,7 +82,12 @@ XfroutClient::sendXfroutRequestInfo(const int tcp_sock,
 
     // TODO: this shouldn't be blocking send, even though it's unlikely to
     // block.
-    // converting the 16-bit word to network byte order.
+    // Converting the 16-bit word to network byte order.
+
+    // Splitting msg_len below performs something called a 'narrowing
+    // conversion' (conversion of uint16_t to uint8_t). C++0x (and GCC
+    // 4.7) requires explicit casting when a narrowing conversion is
+    // performed. For reference, see 8.5.4/6 of n3225.
     const uint8_t lenbuf[2] = { static_cast<uint8_t>(msg_len >> 8),
                                 static_cast<uint8_t>(msg_len & 0xff) };
     if (send(impl_->socket_.native(), lenbuf, sizeof(lenbuf), 0) !=