...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stddef.h> /* For size_t */
static const size_t _max_limit = 1024;
size_t _limit = 100;
unsigned int getValue(unsigned int count) {
return count < _limit ? count : _limit;
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stddef.h> /* For size_t */
static const size_t max_limit = 1024;
size_t limit = 100;
unsigned int getValue(unsigned int count) {
return count < limit ? count : limit;
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <inttypes.h> /* For int_fast16_t and PRIdFAST16 */ #include <stdio.h> /* For sprintf and snprintf */ static const int_fast16_t INTFAST16_LIMIT_MAX = 12000; void print_fast16(int_fast16_t val) { enum { MAX_SIZE = 80 }; char buf [MAX_SIZE]; if (INTFAST16_LIMIT_MAX < val) { sprintf(buf, "The value is too large"); } else { snprintf(buf, MAX_SIZE, "The value is %" PRIdFAST16, val); } /* ... */ } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <inttypes.h> /* For int_fast16_t and PRIdFAST16 */ #include <stdio.h> /* For sprintf and snprintf */ static const int_fast16_t MY_INTFAST16_UPPER_LIMIT = 12000; void print_fast16(int_fast16_t val) { enum { BUFSIZE = 80 }; char buf [BUFSIZE]; if (MY_INTFAST16_UPPER_LIMIT < val) { sprintf(buf, "The value is too large"); } else { snprintf(buf, BUFSIZE, "The value is %" PRIdFAST16, val); } /* ... */ } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stddef.h> /* For size_t */ void* malloc(size_t nbytes) { void *ptr; /* Allocate storage from own pool and set ptr */ return ptr; } void free(void *ptr) { /* Return storage to own pool */ } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stddef.h> /* For size_t */ void* my_malloc(size_t nbytes) { void *ptr; /* Allocate storage from own pool and set ptr */ return ptr; } void* my_calloc(size_t nelems, size_t elsize) { void *ptr; /* Allocate storage from own pool and set ptr */ return ptr; } void* my_realloc(void *ptr, size_t nbytes) { /* Reallocate storage from own pool and set ptr */ return ptr; } void my_free(void *ptr) { /* Return storage to own pool */ } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stddef.h> /* For size_t */ #include <stdlib.h> /* General utilities */ void *malloc(size_t nbytes) { /* Violation */ void *ptr; /* ... */ /* Allocate storage from own pool and set ptr */ return ptr; } void free(void *ptr) { /* Violation */ /* ... */ /* Return storage to own pool */ } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stddef.h> /* For size_t */ void *malloc_custom(size_t nbytes) { void *ptr; /* ... */ /* Allocate storage from own pool and set ptr */ return ptr; } void free_custom(void *ptr) { /* ... */ /* Return storage to own pool */ } |
...