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: 

warning: variable 'av' is uninitialized when used here

This warning seems incorrect in this case:

 

#include "stdio.h"

union act_val{
    double a;
    int b;
};

void thing2(union act_val av)
{
    printf("%d\n", av.b);
}

int main(int argc, char const *argv[])
{
    union act_val av;

    av.b = 1;
    thing2(av);

    return 0;
}

Variable av is uninitialized when used here, at the thing2 call. The warning goes away if the 'a' field is an 'int'. I suppose it is warning me that not all the bytes of the union are being initialised, as double is larger than int here. It seems like half the reason for a union is to be able to deal with a specific field at a time. 

 

Of course I can work around the warning by initialising the 'a' field, I do not like the initialise variables with false values however as it stops genuine warnings and valgrind errors. 

 

0 Kudos
Message 1 of 4
(6,960 Views)

Hi evanb,

 

It seems that LabWindows/CVI performs only minimal checks for union type variables. If a union contains pointers, arrays, or structs, LabWindows/CVI does not maintain user protection information for those objects.

 

I found that in this link  http://zone.ni.com/reference/en-XX/help/370051M-01/cvi/programmerref/unions/

 

Have a great day.

0 Kudos
Message 2 of 4
(6,925 Views)

Hello,

Thanks for the reference, but it does not seem relevant here. My union does not contain a pointer, array, or struct. It is not obvious, but that doc might be referencing run time, while I am talking about compile time. I was also under the impression that cvi used clang to compile, clang does not give the same warning, even with -Weverything. The doc is dated 2008, I am using CVI 2017.

 

Thanks

0 Kudos
Message 3 of 4
(6,918 Views)

Hi, 

Also, this is the documentation that you can find on CVI Help.

 

 I want to mention this forum, https://forums.ni.com/t5/LabWindows-CVI-Idea-Exchange/idb-p/cviideas normally R&D check out this if you have great ideas or thing that you may want to change on CVI. 

 

I found this about clang, https://forums.ni.com/t5/Community-Documents/How-to-build-and-integrate-lastest-clang-compiler-to-CV...

 

On the readme file of CVI 2017, 

The following components and features were deprecated in LabWindows/CVI 2017:

  • NIReports
  • MStudioCW3DGraph
  • Merge Modules installed by LabWindows/CVI in system's merge module directory (C:\Program Files\Common Files\Merge Modules).
  • Support for LabWindows/CVI Library with .NET 1.1 and 2.0
  • LabWindows/CVI versions of the Clang 2.6 and 2.9 compilers shipped with LabWindows/CVI
0 Kudos
Message 4 of 4
(6,901 Views)