12-07-2015 04:28 AM
Hello all,
I just received CVI 2015 and I'm trying to recompile one of my projects with it. I receive some new warnings. Some justified, others less so. Yes, I know I can make error messages disapear, but I rather just fix them !
First one is that whenever I use #include <windows.h> I get the following:
WaveFile.c - 5 warnings 7, 1 In file included from c:\Users\dargaud\Devel\Sodar\Sodar2016\Source\WaveFile.c:7: "Windows.h"(213,1) In file included from C:\Program Files (x86)\National Instruments\Shared\MSDTRedistributables\SDKHeaderFiles\8.1\windows.h:213: "windef.h"(24,1) In file included from C:\Program Files (x86)\National Instruments\Shared\MSDTRedistributables\SDKHeaderFiles\8.1\windef.h:24: "minwindef.h"(182,1) In file included from C:\Program Files (x86)\National Instruments\Shared\MSDTRedistributables\SDKHeaderFiles\8.1\minwindef.h:182: "winnt.h"(5320,19) warning: cast from function call of type 'LONG' (aka 'long') to non-matching type 'PVOID' (aka 'void *') [-Wbad-function-cast] "winnt.h"(5345,19) warning: cast from function call of type 'LONG' (aka 'long') to non-matching type 'PVOID' (aka 'void *') [-Wbad-function-cast] "winnt.h"(8682,19) warning: cast from function call of type 'LONG' (aka 'long') to non-matching type 'PVOID' (aka 'void *') [-Wbad-function-cast] "winnt.h"(8693,19) warning: cast from function call of type 'LONG' (aka 'long') to non-matching type 'PVOID' (aka 'void *') [-Wbad-function-cast] "winnt.h"(8704,19) warning: cast from function call of type 'LONG' (aka 'long') to non-matching type 'PVOID' (aka 'void *') [-Wbad-function-cast]
Then the following pragma does not seem to work anymore:
#pragma DisableUninitLocalsChecking
Still gives me a warning later on:
365, 25 warning: variable 'Wave.Data.Mono16' may be uninitialized when used here [-Wuninitialized]
Also the following code now gives me a warning:
void OutputLogMsg(const char *fmt, ... ) { ... va_start( str_args, fmt ); Nb=vsnprintf(Msg, 1022, fmt, str_args);
66, 29 warning: format string is not a string literal [-Wformat]
Reading around I apparently need to use the following:
__attribute__((__format__ (__printf__, 3, 0)))
But it generates:
42, 16 error: 'format' attribute parameter 2 is out of bounds
12-07-2015 05:36 AM
I can comment on your first issue which is very similar to my observation here which was considered in need of a corrective action
12-07-2015 05:41 AM
Thanks. I'd searched for those keywords without success.
For my 3rd issue, I was using the wrong syntax and I fixed it.
12-09-2015 04:29 AM
The 2nd issue still remains.
I noticed something else: I cannot [Generate Help from Source] in HTML anymore, from the documentation tags. Nothing happens. I've tried clean/rebuild and setting/removing this option. I can get a (tiny / wrong ?) XML file that I don't know how to use.
12-10-2015 11:05 AM
Gdargaud,
I just wanted to clarify the situation to make sure that we all understand what the second issue. The #pragmaDisableUninitLocalsChecking is not working as specified.
Just to cover the immediate basis, do you enable the UninitLocalChecking later on in the code after you disable it? Just because the pragma will only operate on the code that is surrounds.
Have you been able to get other #pragma statements working on the computer? The following link has a bunch of #pragma statements that are supported by CVI: http://zone.ni.com/reference/en-XX/help/370051P-01/cvi/programmerref/pragmas/. If you are able to get other statements working, that means at least that these statements are a least being handled properly by the compiler and the issue is that specific statement.
Also is there a way to attach a screenshot of the code that you are working with, so we all can see the flow of the code.
12-17-2015 08:48 AM
Hello StarSarina,
yes, I have
#pragma DisableUninitLocalsChecking for (i=0; i<N; i++) Wave.Data.Mono16[i]=SomeFunc(); SomeOtherFunc(Wave); #pragma EnableUninitLocalsChecking
And it still gives me that warning.
I have some other pragmas in my prog, but based on #pragma clang diagnostic push / ignored / pop
12-17-2015 09:43 AM
Hello gdargaud!
I appreciate your feedback regarding CVI 2015. I would like to request from you that you provide a minimal but fully compilable code snippet that reproduces the problem in CVI 2015. The Uninitialized Locals compiler mechanism performs analysis of the entire local scope of the uninitialized variable in order to determine whether a warning diagnostic should be emitted. Providing a compilable code snippet helps us reproduce the problem and determine a workaround.
Best regards!
- Johannes
11-02-2016 09:01 AM
I've just upgrade my CVI2009 projects to CVI2015. This small function code is well-comipled w/o any warning in CVI2009. How to fix this compiler's bug?
// .................................................................................
// int __stdcall YMDHMS2DateTime(char *as_YMDHMS,char *as_DTstr)
// Conver ByteArray YMDHMS[6] to yyyy/mm/dd hh:mm:ss where Y=YYYY-2000
// BCD--> i.e. Y: 0x11 -->Convert Hex to Dec 10 + 1 = 11 + 2000 = 2011
//Application: MMSP01/02 Sunion RFID Lock
// .................................................................................
int __stdcall eaiYMDHMS2DateTimeStr(unsigned char *as_YMDHMS,unsigned char *as_DTstr)
{
int val[6];
int li_idx, nb[2];
unsigned char *P;
P = as_YMDHMS;
if (strlen(P)==0) return 0;
for (li_idx=0; li_idx < 6; li_idx++) {
val[li_idx] = (int) *P++;
nb[0] = val[li_idx] / 16;
nb[1] = val[li_idx] % 16;
val[li_idx] = nb[0] * 10 + nb[1];
}
sprintf(as_DTstr,"%04d/%02d/%02d %02d:%02d:%02d",val[0] + 2000,val[1],val[2],val[3],val[4],val[5]);
return 1; //ok
}
//Above function is well-compile in CVI 2009, while has lots of warning in CVI2015
//compiler warning message are as followings
Build Status (FastLibDLL90.prj - Release)
FastLibDLL90.c - 128 warnings
2132, 19 warning: variable 'val[li_idx]' may be uninitialized when used here
2122, 5 note: variable 'val' is declared here
2137, 54 warning: variable 'val[0]' may be uninitialized when used here
2122, 5 note: variable 'val' is declared here
2137, 68 warning: variable 'val[1]' may be uninitialized when used here
2122, 5 note: variable 'val' is declared here
2137, 75 warning: variable 'val[2]' may be uninitialized when used here
2122, 5 note: variable 'val' is declared here
2137, 82 warning: variable 'val[3]' may be uninitialized when used here
2122, 5 note: variable 'val' is declared here
2137, 89 warning: variable 'val[4]' may be uninitialized when used here
2122, 5 note: variable 'val' is declared here
2137, 96 warning: variable 'val[5]' may be uninitialized when used here
2122, 5 note: variable 'val' is declared here
...
Link FastLibDLL90.dll
"e:\CVI15\1proj\FastLibDLL90\FastLibDLL90.dll" successfully created.
"e:\CVI15\1proj\FastLibDLL90\FastLibDLL90.lib" successfully created.
"e:\CVI15\1proj\FastLibDLL90\msvc\FastLibDLL90.lib" successfully created.
"C:\Windows\SysWoW64\FastLibDLL90.dll" successfully created.
Build succeeded.
11-03-2016 04:53 AM
Just found out: if you use the __attribute__ thing in a DLL, e.g. add a function like this to the CVI DLL sample,
DLLEXPORT void __stdcall DLLFunc3 (const char *fmt, ...) __attribute__((format(printf, 1, 2)));
the resource compiler freaks out
Build Status (cvidll.prj - Debug) Resource compiler errors Microsoft (R) Windows (R) Resource Compiler Version 6.3.9600.17200 Copyright (C) Microsoft Corporation. All rights reserved. c:\[...]\Documents\National Instruments\CVI2015\samples\dll\basic\cvibuild.cvidll\Debug\resources.out.rc(47) : error RC2104 : undefined keyword or key name: printf Build failed.
Anyway...
@Jedidiah
a) I'd change "char *as_YMDHMS" to "const char *as_YMDHMS" (bonus point for coding style)
b) kill the for loop and just use a sprintf, like
sprintf(as_DTstr,"20%02x/%02x/%02x %02x:%02x:%02x",as_YMDHMS[0],as_YMDHMS[1],as_YMDHMS[2],as_YMDHMS[3],as_YMDHMS[4],as_YMDHMS[5]);
(not tested)
11-03-2016 04:56 AM
Try to put the __attribute__ before the function name. I've had this problem a few days ago, but I'm not sure on which compiler it helped !