Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

membervar as array in astruct

Status
Not open for further replies.

homeless

Programmer
Nov 6, 2001
20
0
0
CH
I try to set the data Array form the following struct
Code:
typedef enum{ DIES,DAS }MessageType;
typedef struct{MessageType type;
                unsigned long data[32];
}TriggerData;

in main:

Code:
 int main(int argc, char* argv[]){

TriggerData sValue;
                    
                    sValue.data = { 0x00000013,0x00000033,0x00000023,0x00000000,
                                    0x00000000,0x00000000,0x00000000,0x00000000,
                                    0x00000000,0x00000000,0x00000000,0x00000000,
                                    0x00000000,0x00000000,0x00000000,0x00000000,
                                    0x00000000,0x00000000,0x00000000,0x00000000,
                                    0x00000000,0x00000000,0x00000000,0x00000000,
                                    0x00000000,0x00000000,0x00000000,0x00000000,
                                    0x00000000,0x00000000,0x00000000,0x00000000 };
                          
 sValue.type = DIS;


and become an Syntaxerror on line Syntaxfehler sValue.data = { 0x.......
 
This should work :

Code:
#include <string.h>

typedef enum{ DIES,DAS }MessageType;
typedef struct{MessageType type;
                unsigned long data[32];
}TriggerData;

int main(int argc, char* argv[])
{
  TriggerData sValue;
  unsigned long filled_data[32] =
    { 0x00000013,0x00000033,0x00000023,0x00000000,
      0x00000000,0x00000000,0x00000000,0x00000000,
      0x00000000,0x00000000,0x00000000,0x00000000,
      0x00000000,0x00000000,0x00000000,0x00000000,
      0x00000000,0x00000000,0x00000000,0x00000000,
      0x00000000,0x00000000,0x00000000,0x00000000,
      0x00000000,0x00000000,0x00000000,0x00000000,
      0x00000000,0x00000000,0x00000000,0x00000000 };
  memcpy (sValue.data, filled_data, 32 * sizeof (unsigned long));
  sValue.type = DIES;

 return 0;
}

Fixed C++ arrays must be initialized with {...} when declared.

--
Globos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top