Repository navigation
Open
Description
typeof is available in C23 as well as GCC and Clang as extensions (might need __typeof__ depending on flags)
See:
I'm not sure how to organize this into the existing examples though. Here's my attempt at using typeof on everything in the C section, with original as comparison. Some of these aren't really better.
Note that I haven't tested these.
As a variable:
returnType (*variableName)(parameterTypes) = function_name;
typeof(returnType (parameterTypes)) *variableName = function_name;As a static const variable:
static returnType (* const variableName)(parameterTypes) = function_name;
static typeof(returnType (parameterTypes)) * const variableName = function_name;As an array:
returnType (*arrayName[])(parameterTypes) = {function_name0, ...};
typeof(returnType (parameterTypes)) *arrayName[] = {function_name0, ...};As a parameter to a function:
int my_function(returnType (*parameterName)(parameterTypes));
int my_function(typeof(returnType (parameterTypes)) *parameterName);As a return value from a function:
returnType (*my_function(int, ...))(parameterTypes);
typeof(returnType (parameterTypes)) *my_function(int, ...);As a cast (but try not to cast functions):
... (returnType (*)(parameterTypes))my_expression ...
... (typeof(returnType (parameterTypes)) *)my_expression ...As a function pointer typedef:
typedef returnType (*typeName)(parameterTypes);
typedef typeof(returnType (parameterTypes)) *typeName;As a function typedef:
typedef returnType typeName(parameterTypes);
typedef typeof(returnType (parameterTypes)) typeName;Metadata
Metadata
Assignees
Labels
No labels
Activity
jerryryle commentedon Apr 20, 2025
Thanks for the suggestion! The typeof syntax seems notable enough that it'd be worth including. I'll look into it when I can, though it might be a little while before I can get to it.