Problems with structure+union 
Author Message
 Problems with structure+union

/      // LOOK HERE !!!!!!!
/ union { struct { HWND hInputN[4],hInputDS[3],hInputDE[3]; }   ;
                                                            ^^^^^
                          You need to name this union member here.
                                            Mayhaps the name hstr.

/         HWND hInput[10];
/       } h;
/      // LOOK HERE !!!!!!!
/

/              h.hInput[0]  =  h.hstr.hInputN[0]
/              h.hInput[1]  =  h.hstr.hInputN[1]
/              h.hInput[2]  =  h.hstr.hInputN[2]
/              h.hInput[3]  =  h.hstr.hInputN[3]
/                         ----------------------------
/                             array of HWND 'hInputDS'
/                         ----------------------------
/              h.hInput[4]  =  h.hstr.hInputDS[0]
/              h.hInput[5]  =  h.hstr.hInputDS[1]
/              h.hInput[6]  =  h.hstr.hInputDS[2]
/                         ----------------------------
/                             array of HWND 'hInputDE'
/                         ----------------------------
/              h.hInput[7]  =  h.hstr.hInputDE[0]
/              h.hInput[8]  =  h.hstr.hInputDE[1]
/              h.hInput[9]  =  h.hstr.hInputDE[2]

--
Collective Against Consensual Sanity
v0.1 is sort of up.   http://www.*-*-*.com/
For a free CACS T-shirt send $42 shipping and handling.
pretty?     http://www.*-*-*.com/



Sat, 06 Apr 2002 03:00:00 GMT  
 Problems with structure+union

Don't care of the various #include & #pragma statement and look at
this code:

----------------------------------------------------------------------
#include <vcl\vcl.h>

     // LOOK HERE !!!!!!!
union { struct { HWND hInputN[4],hInputDS[3],hInputDE[3]; };
        HWND hInput[10];
      } h;
     // LOOK HERE !!!!!!!

#pragma hdrstop
#include "declaration.h"
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
 : TForm(Owner)
{
h.hInput[0] =(void*) 12;
h.hInput[5] =(void*) 143;
h.hInput[7] =(void*) 6;
h.hInputN[1] =(void*) 4;
for (int i=0; i==9; i++)
  h.hInput[i] =(void*) i;

Quote:
}

----------------------------------------------------------------------

Well what I'm triyng 2 do this time is to have a structure (what is
represented by "h" in the source above) which perform something like
the following:

array of HWND 'hInput'  |   array of HWND 'hInputN' |
------------------------|---------------------------|
             hInput[0]  =  hInputN[0]
             hInput[1]  =  hInputN[1]
             hInput[2]  =  hInputN[2]
             hInput[3]  =  hInputN[3]
                        ----------------------------
                            array of HWND 'hInputDS'
                        ----------------------------
             hInput[4]  =  hInputDS[0]
             hInput[5]  =  hInputDS[1]
             hInput[6]  =  hInputDS[2]
                        ----------------------------
                            array of HWND 'hInputDE'
                        ----------------------------
             hInput[7]  =  hInputDE[0]
             hInput[8]  =  hInputDE[1]
             hInput[9]  =  hInputDE[2]
----------------------------------------------------

I'm compiling this chunk of code with C++Builder 1. The code
above (well, surprisingly) compile & execute fine.

When I try to move the the union declaration on the 1st line,
(everything between the 'LOOK HERE' lines) I get the follwing
errors:

1. Type name expected (after the 2nd '{' )

   Fine. But why the compiler didn't complain about this when
   the code is like reported above ?

2. Declaration missing ; (always after the 2nd '{' )

   Is it illegal to nest union & structures ?
   Well, fine. But, again, why did compile it before ?

3. Type name expected (this time after hInput)

   One for union, one or struct, right?

4. Declaration missing ; (this time after hInput)

   same as 3

5. Obviously, the daclaration is illegal, an so all the h. variables
   used after its declaration.

The rest of the program should not affect on this particular topic,
I can't figure out why putting the declaration above the #include
can solve anything.

Briefly my questions:
Q1- What magic should solve the errors in the marvelous vcl.h at the
    1# line ? = Why moving to the 1# line trigger that errors ?
Q2- Is it this declaration damn wrong ? ***WHY*** ?
    There's something else which could do the job ?

PLEASE!!!!!!!!!!!!! Do not give me only the solution!
PLEASE!!!!!!!!!!!!! Try to explain!

Thanks.

    (_mm_)                                          (_mm_)
     (Oo)        ^     |         (    |              (--)
~,-,_/()      / \ n o| r e a    ) a | m a $ o     ()\_,-,~

 \   (  )                                            (  )   /
  |~| ||    Do NOT Reply!! Use the address above!     || |~|
   n n nn      O==m PGPkeyavailable ICQ5242052       nn n n



Sun, 07 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Question regarding unions and structures

2. fread w/ Union structures

3. Structures vs. Unions

4. Initialising Union members of Structures

5. Bit-fields, unions and structures...

6. structure, union & enumeration tags

7. help: unnamed unions within structures

8. Union within structures

9. Alignment of data in a Structure/Union

10. structure union mess

11. Structures & Unions

12. Structure and union.

 

 
Powered by phpBB® Forum Software