Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which rule to use for C11 _Generic? #131

Open
ghost opened this issue Jun 20, 2018 · 2 comments
Open

Which rule to use for C11 _Generic? #131

ghost opened this issue Jun 20, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Jun 20, 2018

While working on dotnet/corefx#30495, I realized that clang-format has transformed:

#define LIMIT_MAX(T) _Generic(((T)0), \
  unsigned int: UINT_MAX,             \
  unsigned long: ULONG_MAX,           \
  unsigned long long: ULLONG_MAX)

into:

#define LIMIT_MAX(T) _Generic(((T)0),              \
                              unsigned int         \
                              : UINT_MAX,          \
                                unsigned long      \
                              : ULONG_MAX,         \
                                unsigned long long \
                              : ULLONG_MAX)

and couldn't quite figure out which *colon* rule needs to be set to leave alone _Generic block: https://clang.llvm.org/docs/ClangFormatStyleOptions.html.

@jhunterkohler
Copy link

Hello from the future; I too do not know.

@ailijic
Copy link

ailijic commented Dec 9, 2021

This is a workaround. Define a macro that can be used for each line of _Generic, the macro allows you to omit the colon. Then using the Mozilla style you get the following.

#define GEN_LINE(type, fn)                                                     \
  type:                                                                        \
  fn

#define absValue(m)                                                            \
  _Generic((m),                                                                \
           GEN_LINE(F32, F32_absValue),                                        \
           GEN_LINE(F64, F64_absValue),                                        \
           GEN_LINE(F80, F80_absValue),                                        \
           GEN_LINE(int, Int_absValue),                                        \
           GEN_LINE(long, Long_absValue),                                      \
           GEN_LINE(long long, LongLong_absValue))(m)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants