Skip to content

Macros using C23/GNU C typeof specifiers to improve function pointer and array syntax

License

Notifications You must be signed in to change notification settings

MykBamberg/betterctypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

betterctypes

This simple header file defines macros that allow for easily readable left-to-right type specifiers for arrays and function pointers.

Arrays

Traditional C

int array[128];
const int* array[128];
int* const array[128];
const int* const array[128];

betterctypes

arr(/* type */ int, /* length */ 128) array;
arr(const int*, 128) array;
const arr(int*, 128) array;
const arr(const int*, 128) array;

Function pointers

Traditional C

void (*function_pointer)(int, int);
void (*function_pointer)(int, int (*)(int));
void (*(*function_pointer)(int))(int);

betterctypes

fn(/* return type */ void, /* parameter types */ int, int) function_pointer;
fn(void, int, fn(int, int)) function_pointer;
fn(fn(void, int), int) function_pointer;

/* new possibility */
fn(void, int) func1, func2;

About

Macros using C23/GNU C typeof specifiers to improve function pointer and array syntax

Topics

Resources

License

Stars

Watchers

Forks

Languages