0

Quick question: My code makes extensive Code of macros, let's say it's a macro named X. That macro takes some code as a parameneter, like that: X(const int i;)

If that code contains an error, most compilers give me a rather long error message, looking like that: - In Macro Expanded From X in Y - In Macro Expanded From ... - Error about the actual code.

Is there an option is popular compilers to suppress the first two lines? It makes error messages unreadable, and they are of no use, since the error is in code anyway, not in the macro.

Thanks!

  • 2
    Why exactly don't you find that useful? I would imagine that knowing a macro is involved would be helpful (or at least in some cases). –  May 02 '20 at 06:50
  • Are you aware that macros in C++ are a bad choice usually? Macros are namespace agnosting and might be replaced where it isn't expected. Have you ever wondered why `int n1, n2;` ... `int n = std::min(n1, n2);` is a syntax error? (until you prefixed this with `#undef min`) ;-) – Scheff's Cat May 02 '20 at 07:02
  • I know, but this is something only macros can implement –  May 02 '20 at 07:05
  • @Chipster I know this can be helpful, but in this case, it just bloatens the error message –  May 02 '20 at 07:06
  • I'd suggest it is quite likely that, if you posted a question in the form "I do XYZ with macros. Are there effective options that can achieve the same thing without macros?" where "XYZ" describes accurately what you are doing with macros, then you will probably get some useful advice on how to write your particular code without macros. There are some circumstances where macros are genuinely useful but, more often than not, there are language features in C++ that can achieve the same effect more efficiently and easily. – Peter May 02 '20 at 07:30
  • 1
    To address the question as asked, the way your compiler formats diagnostics is often specific to your compiler. Read documentation for your compiler (or IDE) to see if it supports options to format diagnostics in a better way. – Peter May 02 '20 at 07:33

0 Answers0