Results for “memo”
Small, practical examples. Search by task or narrow things down below.
Allocate an independent copy of a C string
C: Include one extra byte for the terminating null character.
C✓ Tested
Allocate and free a typed array
C: Use sizeof on the pointed-to type and check allocation success before writing.
C✓ Tested
Allocate and initialize a structure
C: Use a compound literal assignment to initialize all ordinary structure fields.
C✓ Tested
Check an array allocation size before multiplying
C: Compare the requested element count against SIZE_MAX divided by element size.
C✓ Tested
Check EEPROM capacity before a write
Arduino / C: length reports the available address count for this board.
Arduino / C✓ Tested
Clear an owning pointer after releasing its allocation
C: Assigning NULL helps prevent accidental reuse through the same variable.
C✓ Tested
Copy a flash string into a bounded RAM buffer
Arduino / C: strncpy_P reads from program memory into ordinary RAM.
Arduino / C✓ Tested
Create an independent copy of a byte buffer
C: Allocate the exact byte length and copy only after checking the result.
C✓ Tested
Grow an allocation without losing it on failure
C: Assign realloc to a temporary pointer so the original allocation remains available if growth fails.
C✓ Tested
Initialize a byte buffer to zero
C: memset initializes each byte to the chosen unsigned-char value.
C✓ Tested
Read 16-bit values from a flash table
Arduino / C: pgm_read_word retrieves a complete word from program memory.
Arduino / C✓ Tested
Read a byte lookup table from flash
Arduino / C: PROGMEM tables require the AVR program-memory access functions.
Arduino / C✓ Tested