Tag: #semantics
What is
extern
in C? extern
declares a variable without defining it, allowing the linker to find the definition elsewhere. This is useful when a variable is declared in one file but defined in another. 2017-08-27What is the type of a constant in C?
Integers in C are
int
by default, while suffixes like L
and U
denote long
and unsigned
types. Floats are double
without a suffix. 2017-01-23What is the difference between C constants and C literals?
Literals are lvalues with addresses, while constants are rvalues without addresses. In C, only string literals are literals; other “literals” like numbers and characters are constants. 2017-01-22
What are lvalue and rvalue in C?
“lvalue” either means “expression which can be placed on the left-hand side of the assignment operator”, or means “expression which has a memory address”. “rvalue” is defined as “all other expressions”. 2017-01-21
What is a
union
in C? A
union
in C allows one variable to hold different data types, where the storage is shared. The size of a union
is at least the size of its largest member. Fields in a union
have the same byte offset. 2017-01-03What are ‘statement expressions’ in GCC?
GCC’s ‘statement expressions’ allow inserting statements into expression positions. Behavior is unspecified. 2016-12-30
How do I put an array in a struct in C?
C allows a single array field of incomplete type (
char []
) at the end of a struct definition. The size of the struct is determined by the size of the fixed fields, and the dynamic-sized array is allocated separately. 2016-12-27How to write an array literal in C (with explicit indexes)
C array literals can use explicit indexes. The array length is determined by the largest explicit index. 2016-12-25
What are
static
functions in C? static
functions in C are only callable within the translation unit they are defined in, not across the whole program. 2016-12-12What is ‘array decaying’ in C?
Arrays in C can “decay” to pointers, but are not inherently pointers. The size of an array is lost during decay. 2016-12-08
What does the
restrict
keyword mean in C? The
restrict
keyword in C is a type qualifier that indicates a pointer parameter points to an object not accessed through any other pointer in the function’s scope. This allows the compiler to make optimizations. 2016-12-03What does
const
mean in C? const
is a type qualifier in C that makes a variable unassignable, except during initialization. 2016-12-02Does C allow pointer arithmetic?
Computing a pointer to unowned memory invokes undefined behavior, even without dereferencing! 2016-11-30
What does
void
mean as a function parameter in C? void
in a C function parameter list means the function takes no arguments, whereas an empty list allows for an unspecified number of arguments. 2016-11-27What is
void
in C? void
in C has multiple meanings: as a return type to indicate no return value, as a parameter type to indicate no parameters, and as a pointer type to indicate a pointer to an unknown type. 2016-11-27All content copyright James Fisher.