FIND YOUR NEXT FEW LINES

Results for “Structures & function interfaces”

Small, practical examples. Search by task or narrow things down below.

135 snippets foundClear filters
CStructures & function interfaces

Group related values in nested structures

C: Nested members model a record that owns another simple record.

C✓ Tested
CStructures & function interfaces

Keep function state between calls

C: A static local variable retains its stored value for the lifetime of the process.

C✓ Tested
CStructures & function interfaces

Pass a function as a callback

C: A typed function pointer permits behavior to be supplied to another function.

C✓ Tested
CStructures & function interfaces

Give a reusable record type a short name

C: A typedef names a structure type without changing its representation.

C✓ Tested
CStructures & function interfaces

Initialize structure fields by name

C: Designated initializers make field assignments independent of their declaration order.

C✓ Tested
CStructures & function interfaces

Iterate over a fixed array of records

C: Compute the array element count with sizeof at the point where it is still an array.

C✓ Tested
CStructures & function interfaces

Keep caller data unchanged by passing a structure by value

C: A value parameter is a copy of the original structure.

C✓ Tested
CStructures & function interfaces

Represent a small set of named states

C: An enum gives symbolic names to integer state values.

C✓ Tested
CStructures & function interfaces

Return a status separately from a calculated result

C: An output pointer lets a function return success or failure independently of its numeric result.

C✓ Tested
CStructures & function interfaces

Track which union member is currently valid

C: An explicit tag tells callers which overlaid union value to read.

C✓ Tested
RustFunctions & data types

Accept different types with a generic function

Accept different types with a generic function in a complete Rust program using the standard library.

Rust✓ Tested
PythonFunctions & error handling

Cache repeated pure function calls

Python: Use lru_cache to avoid recomputing results for identical hashable arguments.

Python✓ Tested