8

I use clang, gcc, and tcc, and I'd like to be able to differentiate between the three in a common header.

Judging by their macro dumps, I expect that the presence of the __clang__ macro will uniquely identify clang.

I'm unable to get a macro dump with tcc ( $compiler -x c -E -dM /dev/null doesn't work in its case ).

What is the macro(s) (if any) that will uniquely identify gcc (and possibly tcc)?

Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
  • Maybe `__GNUC__`? – Kerrek SB Sep 12 '16 at 08:50
  • There are duplicates for gcc, you should really ask only about tcc. – 2501 Sep 12 '16 at 08:52
  • 1
    @KerrekSB clang defines `__GNUC__` too. – Petr Skocik Sep 12 '16 at 08:52
  • I'm afrais [tag:clang] redefine the whole set of predefined macros of [tag:gcc]. So quite difficult to isolate [tag:gcc]. I don't know about [tag:tcc]. – LPs Sep 12 '16 at 08:53
  • @PSkocik: Ah, no luck then. Clang isn't even licensed under a GNU license... Maybe `defined(__GNU__) && !defined(__clang__)`? – Kerrek SB Sep 12 '16 at 08:53
  • @PSkocik if gnuc and !clang – 2501 Sep 12 '16 at 08:54
  • @2501 That works. I checked, and `tcc` doesn't define `__GNUC__`. Thanks. – Petr Skocik Sep 12 '16 at 08:57
  • 2
    Why do you want to do that? Wouldn't it be much more preferable not to rely on compiler-specific quirks and instead stick to the C++ standard? If you really have to test e.g. for the presence of a certain feature, the right question to ask would be how to do that... – Martin Hierholzer Sep 12 '16 at 09:00
  • @MartinHierholzer "If you really have to test e.g. for the presence of a certain feature, the right question to ask would be how to do that...", it would , but I'm not sure if there's a good answer to that one. I know there's autoconf, but I don't want to use anything that combines feature detection with building,& I don't want to run a script per project. Ideally, I'd want something that keeps and updates a macro-based feature list in a global header, and the features macros it would expose would be dependent on the environment (compiler, feature test macros) in which I would include it. – Petr Skocik Sep 12 '16 at 09:40
  • @MartinHierholzer For now, simply switching actions based on the current compiler seems easier, although it is a kind of a hack. – Petr Skocik Sep 12 '16 at 09:41
  • 3
    @MartinHierholzer: sticking to the C++ standard is a very bad idea for **C** code! – too honest for this site Sep 12 '16 at 12:34
  • Sorry, I misread the tag, this is about C and not C++. Still, sticking to the standard might be a good idea, if possible. It just will be a lot harder than in C++. Maybe rethink your choice of language ;-) – Martin Hierholzer Sep 14 '16 at 11:06

1 Answers1

10

Use __TINYC__ to detect tcc1.

Detection of gcc and clang is explained in this StackOverflow question: Detect gcc as opposed to msvc / clang with macro


1 (Quoted from: http://bellard.org/tcc/tcc-doc.html#SEC9)
__TINYC__ is a predefined macro to 1 to indicate that you use TCC.

2501
  • 25,460
  • 4
  • 47
  • 87