[CF-Devel] Patch: some warning cleaning under Win32

crossfire-devel at archives.real-time.com crossfire-devel at archives.real-time.com
Sat Dec 20 19:42:51 CST 2003


Nicolas Weeger wrote:
>
     
      Hum, i have troubles determining the correct type to use for 'char' in 
     
     >
     
      play_sound_player_only's definition.
     
     >
     
     
     >
     
      x & y are chars, ok, and are sent using SockList_AddChar, which takes a 
     
     >
     
      'char'!
     
     >
     
      This char is added to the socket's buffer, which is... unsigned char.
     
     >
     
      Except x & y, since they are relative positions of sound from player, 
     
     >
     
      can be negative!
     
     >
     
     
     >
     
      So at some point, the signed char will be converted to unsigned 
     
     >
     
      (arguably there is no information loss, though, so it isn't too bad).
     
     >
     
      Is it better to fix (x, y) as uint8, and SockList_AddChar too (since 
     
     >
     
      'char' is signed or unsigned depending on platforms, potentially)?
     
     >
     
      Or do i leave x, y as sint8, SockList_AddChar as it is, and let explicit 
     
     >
     
      conversions take care of the rest?
     
     
  The biggest problem here is any mathematic operations done to the values 
either before or after they are passed.

  In terms of passed value, at some level, it shouldn't make a difference, 
because 8 bits are 8 bits.  However, it would seem to be safer for 
SockList_AddChar() to take a uint8, as it just assigns the value to that buffer 
of that same type.

  If the values that are passed in may be negative, you obviously need to use 
sint8 types.  Because try to set negative values for object types that are 
assigned to be positive only is more likely to break than any potential casting 
of the type.




_______________________________________________
crossfire-devel mailing list
     
     crossfire-devel at lists.real-time.com
     
     
     https://mailman.real-time.com/mailman/listinfo/crossfire-devel
     
     
    


More information about the crossfire mailing list