-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix build on big-endian platforms #652
Conversation
SDL_Swap32() and SDL_Swap16() are defined in SDL_endian.h.
SDL_Swap32() and SDL_Swap16() are defined in SDL_endian.h. PR: 242360 Approved by: amdmi3 (maintainer), mentors (implicit approval) Pull Request: ValyriaTear/ValyriaTear#652 git-svn-id: svn+ssh://svn.freebsd.org/ports/head@518858 35697150-7ecd-e111-bb59-0022644237b5
SDL_Swap32() and SDL_Swap16() are defined in SDL_endian.h. PR: 242360 Approved by: amdmi3 (maintainer), mentors (implicit approval) Pull Request: ValyriaTear/ValyriaTear#652
SDL_Swap32() and SDL_Swap16() are defined in SDL_endian.h. PR: 242360 Approved by: amdmi3 (maintainer), mentors (implicit approval) Pull Request: ValyriaTear/ValyriaTear#652 git-svn-id: svn+ssh://svn.freebsd.org/ports/head@518858 35697150-7ecd-e111-bb59-0022644237b5
|
tested and looks fine. thanks! |
|
not sure if it's useful, but why not using [nh]to[nh][ls] functions? Those are C standard functions that aim at making things easier. Basically, consider everything read as if it was read from network (so, n(etwork)toh(ost){l(ong)|s(hort)}) for reading data, and invert n&h for writing? I don't think the save/load performance impact would be big, and it might makes things less dependent on non-standard libraries. |
|
@bmorel looks overkill. This is truely more the goal of SDL and such libs as far as I can see. |
|
Le Wed, 08 Jan 2020 09:25:57 -0800,
Yohann Ferreira <notifications@github.com> a écrit :
@bmorel looks overkill. This is truely more the goal of SDL and such
libs as far as I can see. that said, would you have an example of
code and usage?
Well, now I've just checked the manpage, and noticed the include does
not match anything I remember when I was using windows... but a quick
search gave me the why of things: basically, it's a
POSIX-2001/POSIX-2008 set of functions. In my memory, microsoft was
never really fond of following standards aiming at interop. SDL is much
older than that (but not SDL2, btw) and does include stuff to
workaround that fact (you know, the SDL's fixed integer types? Those
are C standard since 99 at least.).
The include header still changes, though, which could be a good reason
to stick to SDL's version (can't experiment with a windows here, I would
have otherwise).
Let me give you a simple hello world showing the use of those, without
the network stuff, on a linux or Unix system:
=====
#ifdef __WIN32__
#include <winsock.h>
#else
#include <arpa/inet.h>
#endif
#include <stdio.h>
int main()
{
unsigned short short_ = 0xAA80;
printf( "%hx\n", short_ );
short_ = ntohs( short_ );
printf( "%hx\n", short_ );
short_ = htons( short_ );
printf( "%hx\n", short_ );
return 0;
}
=====
Note that I do not remember for certain the symbol used to detect
windows systems.
Also note that the behavior will actually change depending on your
hardware. On Intel architectures, the result will be:
aa80
80aa
aa80
but this should change on other endiannesses, of course.
I would understand that you don't move to that, since honestly, I was
sure it was standard C stuff, and wrong about that.
|
SDL_Swap32() and SDL_Swap16() are defined in SDL_endian.h. PR: 242360 Approved by: amdmi3 (maintainer), mentors (implicit approval) Pull Request: ValyriaTear/ValyriaTear#652
SDL_Swap32() and SDL_Swap16() are defined in SDL_endian.h.