Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22298

Is it possible to define _Generic's association-list dynamically?

$
0
0

I have a template like this:

template.h
----------
// Declare a function "func_type()"
void JOIN(func_, T)(T t) { return; }
#undef T

which I use like this in order to generate the same function for different types:

example.c
---------
#define T int
#include "template.h"

#define T float
#include "template.h"

I would like to have a single func that I can use instead of funct_int, func_float, etc. My problem with _Generic is that it doesn't seem possible to define the association-list dynamically. In practical terms I'd like to have something like this:

#define func(TYPE) _Generic((TYPE), AUTO_GENERATED_LIST)

instead of manually defining every new type like this:

#define func(TYPE) _Generic((TYPE), int: func_int..., float: func_float...)

Here's an example of code that is not working: https://ideone.com/HN7sst


Viewing all articles
Browse latest Browse all 22298

Latest Images

Trending Articles



Latest Images