Skip to content
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

snd_mem: fix build failure on big-endian CPUs with C++11 compilers #886

Merged
merged 1 commit into from Mar 5, 2017

Conversation

smcv
Copy link
Contributor

@smcv smcv commented Oct 29, 2016

The Debian powerpc, mips and s390x builds failed with:

.../code/client/snd_mem.cpp: In function 'qboolean S_LoadSound_Actual(sfx_t*)':
.../code/client/snd_mem.cpp:843:54: error: invalid operands of types '__gnu_cxx::__enable_if<true, double>::__type {aka double}' and 'int' to binary 'operator>>'
        if (sfx->fVolRange < (abs(sfx->pSoundData[i]) >> 8))
                              ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
.../code/client/snd_mem.cpp:845:50: error: invalid operands of types '__gnu_cxx::__enable_if<true, double>::__type {aka double}' and 'int' to binary 'operator>>'
         sfx->fVolRange = abs(sfx->pSoundData[i]) >> 8;
                          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~

This appears to be because sfx->pSoundData[i] is of type short. C++98
only provided int abs(int), long abs(long), float abs(float),
double abs(double) and long double abs(long double) overloads, but
C++11 also provides double abs(T) for all integral types T, including
short. double is not a valid left-hand side for operator>> so
compilation fails.


Compile-tested on one of Debian's remote PowerPC servers. My own PowerPC is in storage, so I can't test this further for a while.

The Debian powerpc, mips and s390x builds failed with:

.../code/client/snd_mem.cpp: In function 'qboolean S_LoadSound_Actual(sfx_t*)':
.../code/client/snd_mem.cpp:843:54: error: invalid operands of types '__gnu_cxx::__enable_if<true, double>::__type {aka double}' and 'int' to binary 'operator>>'
        if (sfx->fVolRange < (abs(sfx->pSoundData[i]) >> 8))
                              ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
.../code/client/snd_mem.cpp:845:50: error: invalid operands of types '__gnu_cxx::__enable_if<true, double>::__type {aka double}' and 'int' to binary 'operator>>'
         sfx->fVolRange = abs(sfx->pSoundData[i]) >> 8;
                          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~

This appears to be because sfx->pSoundData[i] is of type short. C++98
only provided int abs(int), long abs(long), float abs(float),
double abs(double) and long double abs(long double) overloads, but
C++11 also provides double abs(T) for all integral types T, including
short. double is not a valid left-hand side for operator>> so
compilation fails.
@xycaleth xycaleth merged commit cbe2d2a into JACoders:master Mar 5, 2017
@smcv smcv deleted the big-endian branch March 9, 2017 17:31
eternalcodes pushed a commit to eternalcodes/EternalJK that referenced this pull request Aug 21, 2018
snd_mem: fix build failure on big-endian CPUs with C++11 compilers

Former-commit-id: b80d88a
eternalcodes pushed a commit to eternalcodes/EternalJK that referenced this pull request Aug 21, 2018
snd_mem: fix build failure on big-endian CPUs with C++11 compilers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants