08-20-2015 09:21 AM
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...
08-24-2015 07:06 AM
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.
08-24-2015 09:12 AM
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?
08-24-2015 09:16 AM
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
08-24-2015 09:21 AM
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.
08-24-2015 09:28 AM
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.
08-24-2015 09:40 AM
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.
08-24-2015 09:50 AM
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.
08-24-2015 10:07 AM
Thanks
08-25-2015 01:17 AM
just one final side note: this kind of header guard is not needed anymore since clang supports the following directive: