I just realized I have not been receiving notification when you were posting some comments so please accept my apologies. I’ve changed this and should be automatically notified via e-mail now.

Lately, I’ve spent some time with companies porting their software to x64 and it makes days I’m postponing posting an entry, thinking I don’t have the time to make it as interesting as I’d like (“to believe” some would say … J)

So I’ll just start by with a small detail related to SOCKET.

If you also need to run on 32-bit but non Microsoft platforms, you might realize that there, the SOCKET type could map to an int, not a UINT_PTR. So you have a situation where it’s always unsigned on our platform and it can also grow to 64-bit on x64.

What’s the big deal you’ll think, as this is not something that you manipulate (e.g. incrementing, multiplying, ….).

Couple of things:

-      If you store the value in a variable whose type is int or unsigned int, you’ll have some serious issues (warning C4244: 'initializing' : conversion from 'SOCKET' to …, possible loss of data)

-      If you want/need to log the socket value, how do you “print” it? %d or %u won’t be right on x64.
Should you use %Iu? You could if you’re just running on our platform but what if you also run on other ones? (see this and that)

I’ve found %p to be useful for tracing statement that must run on other platforms as a pointer is typically just the right size.

Voilà. I’ll leave it there for now. I’m far from being an expert so I’d love to have comment on this one. Hopefully, I’ll be notified this time!

Next time, I’ll quickly comment on the following code in general and when porting to x64:

   int s = v.size() ;

   for( int i = 0 ; i < s ; i++ ) {

     

   }

À demain si on le veut bien.