0

I have following in my header file

typedef unsigned int FRAMEBIT;

   typedef struct Msg_Node
   {
FRAMEBIT Msg_Id;
FRAMEBIT MSg_Indx;
FRAMEBIT Msg_Size;
struct cmd_Header* pcmd_attr;
struct Msg_Node *pNext;
   }Msg_Node_T;

and in source file

      static Msg_Node_T MSG[ 6 ] = {
        {  0 , 112 , &MSG[1]} ,
        {  113 , 32 , &MSG[2]} ,
        {  146 , 64 ,  &MSG[3]} ,
        {  211 , 72 ,  &MSG[4]} ,
        {  284 , 64 ,  &MSG[5]} ,
        {  349 , 32 , 0} 
      };

and getting an error c2099 initliazer is not a constant how can i remove this error? why this error is coming?

Naidu
  • 139
  • 1
  • 4
  • 13

1 Answers1

0

This code compiles and runs for me without issue in g++ 4.8.1. Did you forget the semicolon after the node_T typedef? I added that and I capitalized node (Edit: you seem to have fixed that in your example). (I also changed a little bit in the MSG initialization but nothing important.) Other than that, the code is the same.

#include <iostream>

typedef unsigned int FRAMEBIT;

typedef struct Node
 {
  FRAMEBIT node_size;
  FRAMEBIT node_index;
  struct Node *pNext;
 }node_T;


 static node_T  MSG[ 4 ] = {
         {  0 , 112 , &MSG[1]} ,
         {  113 , 32 , &MSG[2]} ,
         {  146 , 64 , &MSG[3]} ,
         {  211 , 72 , &MSG[0]}
     };


 int main(){

    //prints 112 as expected
    std::cout << MSG[0].node_index;

    return 0;
 }
Barrett Adair
  • 1,306
  • 10
  • 24
  • no i have it in my code but forgot it while posting it here but still the code isnt working properly ? am working with visual studio – Naidu Mar 19 '14 at 07:47
  • @user3388427:: If you have that in your code, then post the exact code that can reproduce the error. Kindly edit the code in your question. – Abhineet Mar 19 '14 at 07:52
  • i have run it in visual studio 2010. it is not giving any error – Heena Goyal Mar 19 '14 at 07:57
  • i have made some changes in the code that i have posted that is the exact code what am i dealing with – Naidu Mar 19 '14 at 08:04
  • Well, now you need another value in your initializer to account for all 4 struct members – Barrett Adair Mar 19 '14 at 16:04