09-23-2020 11:01 AM
There are some useful compiler warnings I would like to see in the code I am working on (loss of precision and such), but if I crank the Warning level up beyond Common I get tons of warnings from windows header files, such as:
I'd be okay with a flag to ignore those two warnings, so I can see things I am more interested in such as:
Is there a way to ignore specific warnings?
We are using 2017.
Thanks!
Solved! Go to Solution.
09-23-2020 11:07 AM
The help file has helped a bit ... in the Build Options window, where I can select "Warning level:", there is a "..." browse button. It seems to let me uncheck warnings, which I can match from the -Wxxxx text description.
Ideally, I'd like to ignore just the ones in those files, since some could apply to my code, but this may be a start.
09-24-2020 02:27 AM
Hi
I use the following commands to avoid those warning. The commands are inserted into my precompiled header file:
// Do not report system header warnings
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wbad-function-cast" //warning: cast from function call of type A to non-matching type B
#pragma clang diagnostic ignored "-Wtypecheck-convert" //warning: assigning to 'x' from 'y' might lose data
#pragma clang diagnostic ignored "-Wused-but-marked-unused" //warning: 'Function' was marked unused but was used
#pragma clang diagnostic ignored "-Wbad-function-cast" //warning: cast from function call of type A to non-matching type B
#include <windows.h>
#include <shlobj.h>
#pragma clang diagnostic pop
Jan
09-24-2020 08:30 AM - edited 09-24-2020 08:33 AM
You can customize the warnings that are prompted while building the project: goto to Options >> Build options and click on the button highlighted below:
This will lead you to the Compiler Warnings screen where you can choose which of them to activate or not:
Buuu! The damnation of small screens! I dodn't realized this question was already answered! 😞
09-24-2020 10:07 AM - edited 09-24-2020 10:09 AM
Thanks for these answers. As to setting up Build Options, I did that yesterday then spent hours cleaning up compiler warnings in our code. Then, when I started today, I had to do them all again when I was building the Installer package.
I now see they have to be toggled for Release and Build. Do these save with the project?
09-24-2020 10:11 AM
I'll try this in the various spots where we are including <windows.h> and see what happens. Thanks!
I did not realize LabWindows was using Clang. The docs I read say it is not an optimizing compiler. Was Cland being used for the 2017 edition?
09-24-2020 10:27 AM
I am trying this out, manually wrapped around includes of <windows.h> for testing:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wbad-function-cast" //warning: cast from function call of type A to non-matching type B
#pragma clang diagnostic ignored "-Wtypecheck-convert" //warning: assigning to 'x' from 'y' might lose data
#pragma clang diagnostic ignored "-Wused-but-marked-unused" //warning: 'Function' was marked unused but was used
#pragma clang diagnostic ignored "-Wbad-function-cast" //warning: cast from function call of type A to non-matching type B
#include <windows.h>
#pragma clang diagnostic pop
But, then I find errors from <stdint.h> and other standard C files that end up including some CVI files.
26, 1 In file included from c:\Users\huffm\Perforce\allenhuffman\Development\SST\Host\PrecisePower\BandMapOptionsCallbacks.c:26:
"stdint.h"(17,1) In file included from c:\program files (x86)\national instruments\cvi2017\include\ansi\stdint.h:17:
"cvirte.h"(30,9) warning: calling convention '__stdcall' ignored for this target [-Wignored-attributes]
"cvidef.h"(122,29) note: expanded from macro 'CVIFUNC'
WHAC-A-MOLE continues 🙂 I see this -Wignored-attributes was not in your list. Are not not including anything like stdint.h that would require this?
Thanks for these replies, folks!
09-24-2020 10:42 AM
The Configuration field (first one in Build Options window) can be set to "All configurations" so your choices are valid in all cases. I don't know if they are saved at project level or not.
09-24-2020 02:09 PM
Thanks, everyone. I am just ignoring them using project options, since I found warnings even when including ANSI C header files like:
#include <stdint.h>
That ends up including some CVI files that had the issues.
09-24-2020 03:49 PM
For a simple one-file text program, I was able to silence all the warnings by doing this in my main .c file:
//==============================================================================
// Include files
// Do not report system header warnings
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wbad-function-cast"
#pragma clang diagnostic ignored "-Wpadded"
#pragma clang diagnostic ignored "-Wundef"
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wused-but-marked-unused"
#include "Windows.h"
#include "asynctmr.h"
#include "CommCtrl.h"
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include "User Interface Application.h"
#include "toolbox.h"
#include <stdbool.h>
#pragma clang diagnostic pop
I suppose anything I include that is not mine is beyond my control, so getting in to the habit of doing this is what I need to do.