From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI 2015: Where are my #pragma messages?

Hi,

 

Compile this:

 

#pragma message ("#PRAGMA MESSAGE") // LINE 1

#pragma GCC warning "#PRAGMA GCC WARNING" // LINE 3

#pragma GCC error "#PRAGMA GCC ERROR" // LINE 5

#warning ("#WARNING 1") // LINE 7

#pragma clang diagnostic ignored "-W#warnings" // LINE 9
#warning ("#WARNING 2") // LINE 10

#error ("#ERROR") // LINE 12

 

 

CVI 2013:

 test.c - 1 error, 5 warnings
  1, 9    warning: #PRAGMA MESSAGE
  3, 13    warning: unknown pragma ignored [-Wunknown-pragmas]
  5, 13    warning: unknown pragma ignored [-Wunknown-pragmas]
  7, 2    warning: #warning is a language extension [-W#warnings]
  7, 2    warning: #warning ("#WARNING 1") // LINE 7 [-W#warnings]
  12, 2    error: #error ("#ERROR") // LINE 12

That's fine. It doesn't know the two "#pragma GCC", which are Clang 3+ (I guess).

 

BUT

 

CVI 2015 file compilation:

  5, 13    error: #PRAGMA GCC ERROR
  7, 2    warning: #warning is a language extension [-W#warnings]
  7, 2    warning: #warning ("#WARNING 1") // LINE 7 [-W#warnings]
  12, 2    error: #error ("#ERROR") // LINE 12

Where are the line 1 (#pragma message) and 3 (#pragma GCC warning) texts?

 

Even more interesting is the interactive window:

 

Interactive Execution - 1 error
 5, 13    error: #PRAGMA GCC ERROR

Where's the rest? CVI 2013 shows everything there, too.

 

 

 

Another thing I find odd: #warning produces 2 warnings with the same flag, thus line 9 disables line 10 (warning 2). So one has the "warning: #warning is a language extension" or no "gcc warnings" at all...

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 1 of 11
(6,359 Views)

Hello CVI-User,

 

CVI doesn't expose all the warnings clang gives because many of them are not relevant(for example are specific to other programming languages)

In this case if someone writes #pragma message I gues he expects to get  the message or a warning/error if it is not supported.

Indeed, clang 3.3 which comes with CVI 2015 recognizes #pragma GCC...

I created a bug, ID 543059 to track the issue, thank you for reporting it.

 

Constantin.

0 Kudos
Message 2 of 11
(6,261 Views)

Hi Constantin,

 

as I understand your post the CAR is only for the #pragma GCC?

 

I am also interested to have the regular message pragma work.

 

Right now,

 

#pragma message ( "C Preprocessor got here!" ) 

 

does not do anything although it should, no?

0 Kudos
Message 3 of 11
(6,250 Views)

Hello Wolfgang,

 

The CAR is both for #pragma message and #pragma GCC warning.

Both pragmas do nothing right now because we don't have the warning in CVI.

 

Constantin

0 Kudos
Message 4 of 11
(6,246 Views)

Thanks for the quick answer!

 

The reason I am asking is that I have the impression that the construct

 

#ifndef INCLUDE_ONCE

#define INCLUDE_ONCE

 

.... // includes, definitions, typdefs ...

 

#endif

 

does not seem to work for me (files are included several times), so I wanted to check with the message pragma.

 

0 Kudos
Message 5 of 11
(6,242 Views)

Hello Wolfgang,

 

So #pragma message is not usable for the moment, until the CAR is fixed.

The header guard should work. Do you have an example when it doesn't work?

 

Constantin.

0 Kudos
Message 6 of 11
(6,236 Views)

Well, I have an example, but it could be well my mistake, that's why I wanted to make sure first...

 

I have a project with several source code and include files, in each source code file I have

 

#include "my_definitions.h"

 

In my_definitions.h I have this guard (or think to have it...):

 

#ifndef INCLUDE_ONCE

#define INCLUDE_ONCE

 

#include <windows.h>

...

 

#endif

 

In the build output, for every source code file, I see an entry

  "Windows.h"(213,1)   In file included from C:\Program Files (x86)\National Instruments\Shared\MSDTRedistributables\SDKHeaderFiles\8.1\windows.h:213:

 

So my conclusion is that windows.h is included every time, not just once.

0 Kudos
Message 7 of 11
(6,232 Views)

Well, the fact that windows.h is included in every source file is expected behaviour. If it was included only in the first compiled file than the subsequent files wouldn't see the definitions from windows.h.

Each file is compiled separately into an object file, so the compiler doesn't have knowledge about the macro definitions from other compilations.

The header guard is for avoiding having the definitions included 2 or more times in the same source files. So if you have in a file

#include "my_definitions.h"
....
#include "my_definitions.h"

windows.h is included only once.

 

Constantin.

 

Message 8 of 11
(6,224 Views)

Thanks Smiley Happy

0 Kudos
Message 9 of 11
(6,221 Views)

just one final side note: this kind of header guard is not needed anymore since clang supports the following directive:

 

#pragma once

0 Kudos
Message 10 of 11
(6,201 Views)