0

I wrote C11 code with heavy macro magic.

MSVC has new preprocessor mode, enabled with /Zc:preprocessor . This mode is perfectly compatible with GCC and Clang preprocessor, so it does macro magic well.

But I want to use expression block language extensions as well, which is perfectly supported by clang-cl.exe.

Unfortunatelly, clang-cl.exe immitates old cl.exe preprocessor, and I found no way to switch it to clang native preprocessor or cl.exe /Zc:preprocessor compatible mode.

For example, following code:

  • compiled well with clang/gcc (unix or mingw)
  • preprocessed right with cl.exe /Zc:preprocessor, but could not be compilled due to "expression block"
  • not preprocessed right with clang-cl.exe (since it immitates cl.exe without new flag), therefore not compilled.
static inline int func(int x) { return x; }
#define get1(...) get1_(__VA_ARGS__)
#define get1_(x, ...) x
#define call(a) ({func(a);})

int main(void)
{
    return call(get1(3,4));
}

Could someone suggest the way to convince clang-cl.exe to do preprocessing right?

funny_falcon
  • 427
  • 3
  • 11
  • Showing a [mre] might help to understand what you want. – Bodo Aug 07 '23 at 11:07
  • @Bodo , I've added example. – funny_falcon Aug 07 '23 at 11:29
  • Why would you need gcc extensions for `({func(a);})` or was this just a poor example? – Lundin Aug 07 '23 at 11:31
  • @StoryTeller-UnslanderMonica , yes, that is why I want to use clang-cl, which perfectly understands statement expressions. – funny_falcon Aug 07 '23 at 11:33
  • @Lundin statement expressions allows to create useful typesafe macros. It is very versatile tool. – funny_falcon Aug 07 '23 at 11:34
  • Yes, I realized I misread. I should point out though that the post's language does require a re-read. – StoryTeller - Unslander Monica Aug 07 '23 at 11:35
  • You shouldn't use these for type safety purposes but to implement multi-line function-like macros in the rare case where an inline function cannot be used. For type safety there's standard `_Generic` and soon to be standard `typeof`. – Lundin Aug 07 '23 at 11:44
  • @Lundin, certainly I use statement expressions for multi-line function-like macros as well. Also _Generic is too restrictive to be very useful. I know why I use statement expressions, you don't need to tell me what they are useful for. – funny_falcon Aug 07 '23 at 11:47

0 Answers0