This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 244274

Summary: Editor error initialising a union in a struct in C
Product: cnd Reporter: develec
Component: Code ModelAssignee: petrk
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P3    
Version: 8.0   
Hardware: Other   
OS: Linux   
Issue Type: DEFECT Exception Reporter:

Description develec 2014-05-04 09:19:04 UTC
Product Version = NetBeans IDE 8.0 (Build 201403101706)
Operating System = Linux version 2.6.32-431.11.2.el6.centos.plus.x86_64 running on amd64
Java; VM; Vendor = 1.7.0_55
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.55-b03

I have written the following test code to demonstrate a (rather obscure) error when writing C in Netbeans.
The error also occurs when using MPLAB X (which is based on NetBeans).

When initialising a struct containing a union, Netbean's editor's parser shows an error (test3). 
However, It does not show any error when initialising the union when not in a struct (test 0 and test1).
This code compiles and runs correctly (even in the debugger) and changes the value of answer to -299990:

/*-----------------------------------------------------------------------------------------------------------*/
typedef union {
  unsigned char unsignedChar;
  long signedLong;
} UnionTypeTest;

typedef struct {
  long answer;
  UnionTypeTest testData;
} UnionMemberStruct;

/* No errors here */ 
UnionTypeTest test0 = {.signedLong = (long) - 100000};
UnionTypeTest test1 = {.unsignedChar = (unsigned char) 10};

/* BUG: This line shows an error -
 * "Unable to resolve identifier signedLong." in the editor
 * It compiles correctly however using the c compiler. */
UnionMemberStruct test3 = {34,
  {.signedLong = (long) - 200000}};

/*
 *
 */
int main() {

  test3.answer =
          test0.signedLong +
          test1.unsignedChar +
          test3.testData.signedLong;

  while (1);

  return (EXIT_SUCCESS);
}
/*-----------------------------------------------------------------------------------------------------------*/

Hope this helps

Kind regards

Jeff
Comment 1 petrk 2015-10-27 19:53:08 UTC

*** This bug has been marked as a duplicate of bug 255328 ***