c - _Generic: multiple types to a single value? -


using c11 _generic there way map multiple types single value?

eg:

_generic(e,      \     *:    foo_expression, \     b **:   foo_expression, \     c:      foo_expression, \     enum d: bar_expression, \     void *: bar_expression) 

is there way group types? (this isn't valid syntax express intent)

_generic(e, \     *: b **: c:    foo_expression, \     enum d: void *:  bar_expression) 

the reason ask args foo , baz can end being large expressions (which can't refactored functions), way avoid lot of duplication good.


note:

if there no supported way using _generic, _could_ make varargs macro glue multiple args single value...

#define generic_type_glue3(answer, arg0, arg1) \     arg0: answer, arg1: answer #define generic_type_glue4(answer, arg0, arg1, arg2) \     arg0: answer, arg1: answer, arg2: answer .... 

... have many of these macros, use varargs wrapper automatically use right one, see: https://stackoverflow.com/a/24837037/432509

_generic(e,      \     generic_type_glue(foo_expression, short int, long),     generic_type_glue(bar_expression, float, double)) 

(see working example: https://gist.github.com/ideasman42/4426f255880ff6a53080)

no, similar switch there no syntax foreseen regroup multiple cases _generic. regrouping macro approach correct 1 purpose, then. may have macro meta programming done boost or package p99 allow have 1 such macro counting of cases for.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -