本文整理汇总了C++中COMPILE_TIME_ASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ COMPILE_TIME_ASSERT函数的具体用法?C++ COMPILE_TIME_ASSERT怎么用?C++ COMPILE_TIME_ASSERT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了COMPILE_TIME_ASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_mpi
/*
* Initializes a MPI.
*
* A temporary MPI is allocated and if a bigInt is supplied the MPI is
* initialized with the value of the bigInt.
*/
static void get_mpi(mbedtls_mpi *mpi, const TEE_BigInt *bigInt)
{
/*
* The way the GP spec is defining the bignums it's
* difficult/tricky to do it using 64-bit arithmetics given that
* we'd need 64-bit alignment of the data as well.
*/
COMPILE_TIME_ASSERT(sizeof(mbedtls_mpi_uint) == sizeof(uint32_t));
/*
* The struct bigint_hdr is the overhead added to the bigint and
* is required to take exactly 2 uint32_t.
*/
COMPILE_TIME_ASSERT(sizeof(struct bigint_hdr) ==
sizeof(uint32_t) * BIGINT_HDR_SIZE_IN_U32);
mbedtls_mpi_init_mempool(mpi);
if (bigInt) {
const struct bigint_hdr *hdr = (struct bigint_hdr *)bigInt;
const mbedtls_mpi_uint *p = (const mbedtls_mpi_uint *)(hdr + 1);
size_t n = hdr->nblimbs;
/* Trim of eventual insignificant zeroes */
while (n && !p[n - 1])
n--;
MPI_CHECK(mbedtls_mpi_grow(mpi, n));
mpi->s = hdr->sign;
memcpy(mpi->p, p, n * sizeof(mbedtls_mpi_uint));
}
}
示例2: Sqrt
typename xtl::TypeTraits<T>::LengthType Sqrt(const T& a)
{
typedef typename xtl::TypeTraits<T>::LengthType LengthType;
COMPILE_TIME_ASSERT(xtl::TypeTraits<T>::IsArithmetic);
COMPILE_TIME_ASSERT(xtl::TypeTraits<LengthType>::IsReal);
return sqrt(xtl::RealCast<LengthType>(a));
}
示例3: COMPILE_TIME_ASSERT
void CSocketAddress::ApplyStunXorMap(const StunTransactionId& transid)
{
const size_t iplen = (_address.addr.sa_family == AF_INET) ? STUN_IPV4_LENGTH : STUN_IPV6_LENGTH;
uint8_t* pPort;
uint8_t* pIP;
if (_address.addr.sa_family == AF_INET)
{
COMPILE_TIME_ASSERT(sizeof(_address.addr4.sin_addr) == STUN_IPV4_LENGTH); // 4
COMPILE_TIME_ASSERT(sizeof(_address.addr4.sin_port) == 2);
pPort = (uint8_t*)&(_address.addr4.sin_port);
pIP = (uint8_t*)&(_address.addr4.sin_addr);
}
else
{
COMPILE_TIME_ASSERT(sizeof(_address.addr6.sin6_addr) == STUN_IPV6_LENGTH); // 16
COMPILE_TIME_ASSERT(sizeof(_address.addr6.sin6_port) == 2);
pPort = (uint8_t*)&(_address.addr6.sin6_port);
pIP = (uint8_t*)&(_address.addr6.sin6_addr);
}
pPort[0] = pPort[0] ^ transid.id[0];
pPort[1] = pPort[1] ^ transid.id[1];
for (size_t i = 0; i < iplen; i++)
{
pIP[i] = pIP[i] ^ transid.id[i];
}
}
示例4: super
PackUnix::PackUnix(InputFile *f) :
super(f), exetype(0), blocksize(0), overlay_offset(0), lsize(0)
{
COMPILE_TIME_ASSERT(sizeof(Elf32_Ehdr) == 52);
COMPILE_TIME_ASSERT(sizeof(Elf32_Phdr) == 32);
COMPILE_TIME_ASSERT(sizeof(b_info) == 12);
COMPILE_TIME_ASSERT(sizeof(l_info) == 12);
COMPILE_TIME_ASSERT(sizeof(p_info) == 12);
}
示例5: stm_init
/*
* Called once (from main) to initialize STM infrastructure.
*/
_CALLCONV void
stm_init(void)
{
#if CM == CM_MODULAR
char *s;
#endif /* CM == CM_MODULAR */
#ifdef SIGNAL_HANDLER
struct sigaction act;
#endif /* SIGNAL_HANDLER */
PRINT_DEBUG("==> stm_init()\n");
if (_tinystm.initialized)
return;
PRINT_DEBUG("\tsizeof(word)=%d\n", (int)sizeof(stm_word_t));
PRINT_DEBUG("\tVERSION_MAX=0x%lx\n", (unsigned long)VERSION_MAX);
COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(void *));
COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(atomic_t));
#ifdef EPOCH_GC
gc_init(stm_get_clock);
#endif /* EPOCH_GC */
#if CM == CM_MODULAR
s = getenv(VR_THRESHOLD);
if (s != NULL)
_tinystm.vr_threshold = (int)strtol(s, NULL, 10);
else
_tinystm.vr_threshold = VR_THRESHOLD_DEFAULT;
PRINT_DEBUG("\tVR_THRESHOLD=%d\n", _tinystm.vr_threshold);
#endif /* CM == CM_MODULAR */
/* Set locks and clock but should be already to 0 */
memset((void *)_tinystm.locks, 0, LOCK_ARRAY_SIZE * sizeof(stm_word_t));
CLOCK = 0;
stm_quiesce_init();
tls_init();
#ifdef SIGNAL_HANDLER
if (getenv(NO_SIGNAL_HANDLER) == NULL) {
/* Catch signals for non-faulting load */
act.sa_handler = signal_catcher;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
if (sigaction(SIGBUS, &act, NULL) < 0 || sigaction(SIGSEGV, &act, NULL) < 0) {
perror("sigaction");
exit(1);
}
}
#endif /* SIGNAL_HANDLER */
_tinystm.initialized = 1;
}
示例6: COMPILE_TIME_ASSERT
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CObjectBuffStation::CObjectBuffStation()
{
// Verify networking data.
COMPILE_TIME_ASSERT( BUFF_STATION_MAX_PLAYERS < ( 1 << BUFF_STATION_MAX_PLAYER_BITS ) );
COMPILE_TIME_ASSERT( BUFF_STATION_MAX_PLAYERS >= ( 1 << ( BUFF_STATION_MAX_PLAYER_BITS - 1 ) ) );
COMPILE_TIME_ASSERT( BUFF_STATION_MAX_OBJECTS < ( 1 << BUFF_STATION_MAX_OBJECT_BITS ) );
COMPILE_TIME_ASSERT( BUFF_STATION_MAX_OBJECTS >= ( 1 << ( BUFF_STATION_MAX_OBJECT_BITS - 1 ) ) );
// Uses the client-side animation system.
UseClientSideAnimation();
}
示例7: sanity_checks
static void sanity_checks()
{
COMPILE_TIME_ASSERT(sizeof(convert_64_t) == 8);
COMPILE_TIME_ASSERT(sizeof(convert_32_t) == 4);
COMPILE_TIME_ASSERT(sizeof(stm_word_t) == 4 || sizeof(stm_word_t) == 8);
COMPILE_TIME_ASSERT(sizeof(char) == 1);
COMPILE_TIME_ASSERT(sizeof(short) == 2);
COMPILE_TIME_ASSERT(sizeof(int) == 4);
COMPILE_TIME_ASSERT(sizeof(long) == 4 || sizeof(long) == 8);
COMPILE_TIME_ASSERT(sizeof(float) == 4);
COMPILE_TIME_ASSERT(sizeof(double) == 8);
}
示例8: COMPILE_TIME_ASSERT
XmlNodeRef CScoreIncEvent::GetXML(IGameStatistics* pGS)
{
XmlNodeRef node = pGS->CreateStatXMLNode();
node->setAttr("score", m_score);
COMPILE_TIME_ASSERT(EGRST_Num==ARRAY_COUNT(k_ScoreIncTypeStrs));
EGameRulesScoreType type=m_type;
const char *pStr = "Unknown";
if (m_type>=0 && m_type<ARRAY_COUNT(k_ScoreIncTypeStrs))
{
pStr = k_ScoreIncTypeStrs[m_type];
}
// skip code prefixes from enums to make them more human readable
if (strncmp(pStr,"EGRST_",6)==0)
{
pStr+=6;
}
node->setAttr("type", pStr);
return node;
}
示例9: Square
typename xtl::TypeTraits<T>::AccumType Square(const T& a)
{
COMPILE_TIME_ASSERT(xtl::TypeTraits<T>::IsArithmetic);
typedef typename xtl::TypeTraits<T>::AccumType AccumType;
AccumType b = xtl::RealCast<AccumType>(a);
return b * b;
}
示例10: super
PackVmlinuzI386::PackVmlinuzI386(InputFile *f) :
super(f), physical_start(0x100000), page_offset(0), config_physical_align(0)
, filter_len(0)
{
bele = &N_BELE_RTP::le_policy;
COMPILE_TIME_ASSERT(sizeof(boot_sect_t) == 0x250);
}
示例11: ASSERT
HRESULT CSocketAddress::GetLocalHost(uint16_t family, CSocketAddress* pAddr)
{
if ( ((family != AF_INET) && (family != AF_INET6)) ||
(pAddr == NULL))
{
ASSERT(false);
return E_FAIL;
}
if (family == AF_INET)
{
uint32_t ip = 0x7f000001; // 127.0.0.1 in host byte order
*pAddr = CSocketAddress(ip, 0);
}
else
{
sockaddr_in6 addr6 = {};
COMPILE_TIME_ASSERT(sizeof(addr6.sin6_addr) == 16);
// ::1
uint8_t ip6[16] = {};
ip6[15] = 1;
addr6.sin6_family = AF_INET6;
memcpy(&addr6.sin6_addr, ip6, 16);
*pAddr = CSocketAddress(addr6);
}
return S_OK;
}
示例12: Identify
BOOL Identify(HANDLE hPhysical)
{
ATA_PASSTHROUGH_CMD Command = {0};
IDENTIFY_DEVICE_DATA* idd;
int i, r;
Command.AtaCmd = ATA_IDENTIFY_DEVICE;
// You'll get an error here if your compiler does not properly pack the IDENTIFY struct
COMPILE_TIME_ASSERT(sizeof(IDENTIFY_DEVICE_DATA) == 512);
idd = (IDENTIFY_DEVICE_DATA*)_mm_malloc(sizeof(IDENTIFY_DEVICE_DATA), 0x10);
if (idd == NULL)
return FALSE;
for (i=0; i<ARRAYSIZE(pt); i++) {
r = pt[i].fn(hPhysical, &Command, idd, sizeof(IDENTIFY_DEVICE_DATA), SPT_TIMEOUT_VALUE);
if (r == SPT_SUCCESS) {
uprintf("Success using %s\n", pt[i].type);
if (idd->CommandSetSupport.SmartCommands) {
DumpBufferHex(idd, sizeof(IDENTIFY_DEVICE_DATA));
uprintf("SMART support detected!\n");
} else {
uprintf("No SMART support\n");
}
break;
}
uprintf("No joy with: %s (%s)\n", pt[i].type, SptStrerr(r));
}
if (i >= ARRAYSIZE(pt))
uprintf("NO ATA FOR YOU!\n");
_mm_free(idd);
return TRUE;
}
示例13: COMPILE_TIME_ASSERT
static void *raw_malloc(size_t hdr_size, size_t ftr_size, size_t pl_size)
{
void *ptr = NULL;
size_t s = hdr_size + ftr_size + pl_size;
/*
* Make sure that malloc has correct alignment of returned buffers.
* The assumption is that uintptr_t will be as wide as the largest
* required alignment of any type.
*/
COMPILE_TIME_ASSERT(SizeQuant >= sizeof(uintptr_t));
raw_malloc_validate_pools();
/* Check wrapping */
if (s < pl_size)
goto out;
/* BGET doesn't like 0 sized allocations */
if (!s)
s++;
ptr = bget(s);
out:
raw_malloc_return_hook(ptr, pl_size);
return ptr;
}
示例14: grub_netbuff_alloc
struct grub_net_buff *
grub_netbuff_alloc (grub_size_t len)
{
struct grub_net_buff *nb;
void *data;
COMPILE_TIME_ASSERT (NETBUFF_ALIGN % sizeof (grub_properly_aligned_t) == 0);
if (len < NETBUFFMINLEN)
len = NETBUFFMINLEN;
len = ALIGN_UP (len, NETBUFF_ALIGN);
#ifdef GRUB_MACHINE_EMU
data = grub_malloc (len + sizeof (*nb));
#else
data = grub_memalign (NETBUFF_ALIGN, len + sizeof (*nb));
#endif
if (!data)
return NULL;
nb = (struct grub_net_buff *) ((grub_properly_aligned_t *) data
+ len / sizeof (grub_properly_aligned_t));
nb->head = nb->data = nb->tail = data;
nb->end = (grub_uint8_t *) nb;
return nb;
}
示例15: _cairo_xcb_connection_shm_attach
uint32_t
_cairo_xcb_connection_shm_attach (cairo_xcb_connection_t *connection,
uint32_t id,
cairo_bool_t readonly)
{
struct {
uint8_t req;
uint8_t shm_req;
uint16_t length;
uint32_t segment;
uint32_t id;
uint8_t readonly;
uint8_t pad1;
uint16_t pad2;
} req;
struct iovec vec[1];
COMPILE_TIME_ASSERT (sizeof (req) == 16);
req.req = connection->shm->major_opcode;
req.shm_req = 1;
req.length = sizeof (req) >> 2;
req.segment = _cairo_xcb_connection_get_xid (connection);
req.id = id;
req.readonly = readonly;
vec[0].iov_base = &req;
vec[0].iov_len = sizeof (req);
_cairo_xcb_connection_write (connection, vec, 1);
return req.segment;
}