Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Bug with char/unsigned char?  (Read 3181 times)

0 Members and 1 Guest are viewing this topic.

Manux

  • Newbie
  • *
  • Posts: 23
    • View Profile
Bug with char/unsigned char?
« on: March 12, 2010, 12:52:20 am »
Hello,
I've just stumbled upon a really weird thing, it's either a bug or a misunderstanding from me.

If I put << an sf::Uint8 into a packet, and then >> it out by using a char instead, not only will it not work, but it will affect the rest of the packet!
(I use v1.5 too, maybe I should switch?)

here is the minimal code:
Code: [Select]
sf::Packet p;
std::string s1 = "Hello!";
std::string s2;
int i1 = 1;
int i2 = 5;
int i3,i4;
        //DEFAULT_HEAD is an sf::Uint16 and NPC_DIALOG is a sf::Uint8
p<<DEFAULT_HEAD<<GEVENT_NPC_DIALOG<<i1<<i2<<s1;
unsigned short h;
        //change the type to Uint8 or unsigned char and it will change the output!
//sf::Uint8 t;
        char t;
p>>h>>t>>i3>>i4>>s1;
printf("%d %d %d %d %s\n",h,t,i3,i4,s1.c_str());

Output with char t:
Quote
35812 0 117440512 16777216

Output with uint8
Quote
35812 7 1 5 Hello!
(the proper output)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Bug with char/unsigned char?
« Reply #1 on: March 12, 2010, 08:51:47 am »
Hi

There is no operator >> for the char type, your compiler should output an error with your code (mine does).

sf::Packet handles only fixed-size types (sf::Int8, sf::Uint16, ...). Native types are not safe to send through the network and thus are not directly supported.
Laurent Gomila - SFML developer

 

anything