Replace ARRAYSIZE macro with another ugly macro. At least this will throw an error for a non-array and won't conflict with Windows macro names.

This commit is contained in:
Jordan Woyak
2013-09-11 19:19:36 -05:00
parent ce49964dfe
commit fde3815d34
7 changed files with 45 additions and 33 deletions

View File

@ -12,6 +12,18 @@
#define SLEEP(x) usleep(x*1000)
#endif
#include <cstddef>
// TODO: make into function when type_traits and constexpr are available
template <typename T, std::size_t N = 0>
struct ArraySizeImpl {};
template <typename T, std::size_t N>
struct ArraySizeImpl<T[N], 0> { static const std::size_t size = N; };
// Will fail to compile on a non-array:
#define ArraySize(x) ArraySizeImpl<decltype(x)>::size
template <bool> struct CompileTimeAssert;
template<> struct CompileTimeAssert<true> {};
@ -52,7 +64,7 @@ _mm_shuffle_epi8(__m128i a, __m128i mask)
#else
#define Crash() {asm ("int $3");}
#endif
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
// GCC 4.8 defines all the rotate functions now
// Small issue with GCC's lrotl/lrotr intrinsics is they are still 32bit while we require 64bit
#ifndef _rotl

View File

@ -116,7 +116,7 @@ void GeckoSockServer::ClientThread()
char data[128];
std::size_t got = 0;
if (client.Receive(&data[0], ARRAYSIZE(data), got) == sf::Socket::Disconnected)
if (client.Receive(&data[0], ArraySize(data), got) == sf::Socket::Disconnected)
client_running = false;
if (got != 0)

View File

@ -696,7 +696,7 @@ void ReadHeader()
bongos = tmpHeader.bongos;
bSyncGPU = tmpHeader.bSyncGPU;
bNetPlay = tmpHeader.bNetPlay;
memcpy(revision, tmpHeader.revision, ARRAYSIZE(revision));
memcpy(revision, tmpHeader.revision, ArraySize(revision));
}
else
{
@ -1110,7 +1110,7 @@ void SaveRecording(const char *filename)
header.bProgressive = bProgressive;
header.bDSPHLE = bDSPHLE;
header.bFastDiscSpeed = bFastDiscSpeed;
strncpy((char *)header.videoBackend, videoBackend.c_str(),ARRAYSIZE(header.videoBackend));
strncpy((char *)header.videoBackend, videoBackend.c_str(),ArraySize(header.videoBackend));
header.CPUCore = iCPUCore;
header.bEFBAccessEnable = g_ActiveConfig.bEFBAccessEnable;
header.bEFBCopyEnable = g_ActiveConfig.bEFBCopyEnable;
@ -1123,11 +1123,11 @@ void SaveRecording(const char *filename)
header.bClearSave = g_bClearSave;
header.bSyncGPU = bSyncGPU;
header.bNetPlay = bNetPlay;
strncpy((char *)header.discChange, g_discChange.c_str(),ARRAYSIZE(header.discChange));
strncpy((char *)header.author, author.c_str(),ARRAYSIZE(header.author));
strncpy((char *)header.discChange, g_discChange.c_str(),ArraySize(header.discChange));
strncpy((char *)header.author, author.c_str(),ArraySize(header.author));
memcpy(header.md5,MD5,16);
header.bongos = bongos;
memcpy(header.revision, revision, ARRAYSIZE(header.revision));
memcpy(header.revision, revision, ArraySize(header.revision));
// TODO
header.uniqueID = 0;