LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

struct doesnt compile

Hello All,
Porting some come from  MS VC++ 6.0 to Labwindow/CVI 5.0 under XP
Labwindows can not compile the struct below. I get the error "Field name missing"
with the cursor located on the semi colon after the unions close brace.
 
If I put a name in after the close brace it will compile but then I have other problems.
I compiled this struct  using another ansi c compilier with out problems. 
 
/---------------code-----------------/
 
typedef struct  _GENPORT_WRITE_INPUT {
    ULONG   PortNumber;  // Port # to write to
    union  {               // Data to be output to port
        ULONG   LongData;
        USHORT  ShortData;
        UCHAR   CharData;
    };   
}   GENPORT_WRITE_INPUT;
 
 
/--------------end code ------------/
 
Thanks in advance
 
Joe
0 Kudos
Message 1 of 6
(3,863 Views)
Surely the union must have a name; otherwise how can you refer to its elements later?
 
JR
0 Kudos
Message 2 of 6
(3,861 Views)
I refer to the element like this.
This works, i tested it in VC++
 
/------------------------------------------------------/  
  GENPORT_WRITE_INPUT InputBuffer;
   unsigned short dataValue=10;
 
   InputBuffer.ShortData = dataValue;
  printf(%i,InputBuffer.ShortData);
/-------------------------------------------------------/
 
0 Kudos
Message 3 of 6
(3,854 Views)

How 'bout that! It compiles just fine on my CVI 7.0! All these years I've been doing it the long way... You learn something new every day Smiley Very Happy

JR

0 Kudos
Message 4 of 6
(3,846 Views)
Hello,

Allowing unnamed struct/union fields within an enclosing struct/union is an extension to the C language supported by some compiler vendors, including Microsoft (refer to the Microsoft Specific section on this page).  I don't believe that LabWindows/CVI 5.0 supports this extension, though later versions do.  In order to get your struct to compile in CVI, it looks like you will have to give the field a name.

Hope this helps.

Mert A.
National Instruments

Message Edited by Mert A. on 08-18-2006 10:16 AM

0 Kudos
Message 5 of 6
(3,847 Views)
Or upgrade : )
0 Kudos
Message 6 of 6
(3,836 Views)