[Common-dev] CR-Client: Fix various network API issues

[Common-dev] CR-Client: Fix various network API issues

Tom Marshall tmarshall at helixcommunity.org
Wed Aug 11 08:49:43 PDT 2004


On Wed, Aug 11, 2004 at 08:01:49AM -0700, Aaron Colwell wrote:
> Personally I don't like using #defines to rename functions. Either change the
> names of the actual functions or use the names that already exist. Don't use
> the preprocessor to change the names.  I've seen cases where this causes
> weird unintentional replacement by the preprocessor. Say I have a class that
> implements a function called hx_htonl, but there is a #define hx_htonl swap32
> declaration somewhere. This will cause the member function to get silently
> renamed. You can also get confusing compiler errors if the class also happens
> to have a member function called swap32. You may also get strange linking 
> errors because some code is effected by the #define and others aren't. This
> causes them to expect different symbols for the same function. I realize that
> this a corner case, but I have wasted time on this exact problem before and 
> I'd like to avoid introducing new instances of the same old problem.
> 
> Either rename the functions in netbyte.h to your hx_htonl and friends and
> update all occurances of the old names or change the networking code to use
> the existing names in netbyte.h. The latter seems like the easier of the 2
> to me.

Whatever the method (#define or inline), the endian functions should reduce
to _one_ assembly instruction (bswap) on the x86 and probably most other
platforms.  Calling a function that in turn calls another function that then
does bit shifting to accomplish the task is sub-par to say the least.

-- 
Harrison's Postulate:
        For every action, there is an equal and opposite criticism.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.helixcommunity.org/pipermail/common-dev/attachments/20040811/544d2580/attachment.bin


More information about the Common-dev mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.