const char* init() { // ct_assert must be in a function ct_assert(sizeof(uint32) == 4); ct_assert(sizeof(uint64) == 8); #ifndef __APPLE__ ct_assert(sizeof(size_t) == 8); #endif // Nothing to init right now... no errors possible return NULL; }
int main(int argc, char** argv, char** envp) { COMPILE_TIME_ASSERT(1==1); PR_STATIC_ASSERT(1==1); // this is a built in gcc static assertion, no flags needed _Static_assert(1==1, "fail message"); ct_assert(1==1); STATIC_ASSERT(1==1, fail); // CTC(1==1); return EXIT_SUCCESS; }
TextMessageCreator::CharVectorSPtr &TextMessageCreator::getSessionBuffer(unsigned sessionId, ev_executer_arg(takeBuffer)) { SessionIdBufferMap::iterator it = sessionIdBufferMap.find(sessionId); if (it == sessionIdBufferMap.end()) { CharVectorSPtr newBuffer(std::make_shared<CharVector>()); newBuffer->reserve(bufferSize); std::pair<SessionIdBufferMap::iterator, bool> ret = sessionIdBufferMap.insert(std::make_pair(sessionId, newBuffer)); ct_assert(ret.second); it = ret.first; } return it->second; }
void initEEPROM(void) { // make sure (at compile time) that config struct doesn't overflow allocated flash pages ct_assert(sizeof(mcfg) < CONFIG_SIZE); }
int dac_send_data(dac_t *d, struct dac_point *data, int npoints, int rate) { int res; const struct dac_status *st = &d->conn.resp.dac_status; /* Write the header */ if (st->playback_state == 0) { trace(d, "L: Sending prepare command...\n"); char c = 'p'; if ((res = dac_sendall(d, &c, sizeof(c))) < 0) return res; /* Read ACK */ d->conn.pending_meta_acks++; /* Block here until all ACKs received... */ while (d->conn.pending_meta_acks) dac_get_acks(d, 1500); trace(d, "L: prepare ACKed\n"); } if (st->buffer_fullness > 1600 && st->playback_state == 1 \ && !d->conn.begin_sent) { trace(d, "L: Sending begin command...\n"); struct begin_command b; b.command = 'b'; b.point_rate = rate; b.low_water_mark = 0; if ((res = dac_sendall(d, (const char *)&b, sizeof(b))) < 0) return res; d->conn.begin_sent = 1; d->conn.pending_meta_acks++; } d->conn.local_buffer.queue.command = 'q'; d->conn.local_buffer.queue.point_rate = rate; d->conn.local_buffer.header.command = 'd'; d->conn.local_buffer.header.npoints = npoints; memcpy(&d->conn.local_buffer.data[0], data, npoints * sizeof(struct dac_point)); d->conn.local_buffer.data[0].control |= DAC_CTRL_RATE_CHANGE; ct_assert(sizeof(d->conn.local_buffer) == 18008); /* Write the data */ if ((res = dac_sendall(d, (const char *)&d->conn.local_buffer, 8 + npoints * sizeof(struct dac_point))) < 0) return res; /* Expect two ACKs */ d->conn.pending_meta_acks++; d->conn.ackbuf[d->conn.ackbuf_prod] = npoints; d->conn.ackbuf_prod = (d->conn.ackbuf_prod + 1) % MAX_LATE_ACKS; d->conn.unacked_points += npoints; if ((res = dac_get_acks(d, 0)) < 0) return res; return npoints; }