Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think that strictly speaking, <a href="https://stackoverflow.com/questions/5587655/pragma-not-working/5587695#5587695">Lindydancer's solution</a> needs to be of the form:</p> <pre><code>#define COVERAGE(x) PRAGMA(Coverage_tool x) #define PRAGMA(x) _Pragma(#x) </code></pre> <p>This is the form the standard uses in an example, and it needs to be this way because <code>_Pragma</code> operator processing occurs in a translation phase before string literal concatenation. <code>_Pragma</code> is defined in such a way that it'll only deal with stripping off the leading and trailing quotes when manufacturing the corresponding <code>#pragma</code> - not any other ones that are from 'concatenated' literals.</p> <p>However, your compiler might be tolerant of the other approach (GCC isn't).</p> <p>Note: if the <code>#pragma Coverage_tool</code> pragma needs quotes around the <code>on</code>/<code>off</code> operand, then the <code>COVERAGE</code> macro needs to be:</p> <pre><code>#define COVERAGE(x) PRAGMA(Coverage_tool #x) </code></pre> <p>Note #2: If you're using Microsoft C, I think you want:</p> <pre><code>#define COVERAGE(x) PRAGMA(Coverage_tool x) #define PRAGMA(x) __pragma(x) </code></pre> <p>because Microsoft's directive is spelled slightly differently and, more annoyingly, <em>doesn't</em> want quotes surrounding the argument to the operator.</p> <p>But <code>Coverage_tool</code> isn't a documented pragma supported by MSVC, so I think there's still some important information missing.</p> <p>Since you have some code coverage tool outside of the compiler that's processing this pragma, I think you'll need to hide it from the compiler. The tool will probably define some macro name that it recognizes when it's processing that won't be defined when the compiler is doing its work. For example, lint will define the macro <code>lint</code> when it's processing and Microsoft's resource compiler will define <code>RC_INVOKED</code>.</p> <p>Let's assume that your code coverage tool defines <code>COVERAGE_TOOL</code> when it's running. You might make both tools happy with something like:</p> <pre><code>#if COVERAGE_TOOL #define COVERAGE(x) PRAGMA(Coverage_tool x) #define PRAGMA(x) _Pragma(#x) #else #define COVERAGE(x) #endif </code></pre> <p>But I'm just guessing. I would expect that the docs for the coverage tool would be quite explicit about how these directives need to be integrated into your code if it supports MSVC - you should look there for details (or ask the vendor).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload