Solved

Strange enumeration in GNUC syntax

Posted on 2006-10-27
3
255 Views
Last Modified: 2010-04-15
Hi,

I tried to compile GNUC code in Visual Studio C++ 6.0. I am able to compile all code, except something like this:

typedef enum expr_type {
      X_TYPE,
      A_TYPE,
      B_TYPE,
      MAX_INDEX
} expr_type_enum;

static int x_type_value[MAX_INDEX] =
{
      [ A_TYPE ] = 1,
      [ B_TYPE ] = 2,
      [ B2_TYPE ] = 2,      
};

static enum expr_type expr_x[MAX_INDEX] =
{
      [ 0 ]      = 0,
      [ 1 ]      = A_TYPE,
      [ 2 ]      = B_TYPE,
      [ 3 ]      = 0,
};

How are used those strange "[ Item ]" enumerations? VS Compiler doesn't like it. The last comma is unusual too.

Any suggestions?
0
Comment
Question by:ispaleny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17823906
static int x_type_value[MAX_INDEX] =
{
     [ A_TYPE ] = 1,
     [ B_TYPE ] = 2,
     [ B2_TYPE ] = 2,    
};
initializes x_type_value[ A_TYPE  ]=1; x_type_value[ B_TYPE  ]=2; x_type_value[ B2_TYPE  ]=2;

static enum expr_type expr_x[MAX_INDEX] =
{
     [ 0 ]     = 0,
     [ 1 ]     = A_TYPE,
     [ 2 ]     = B_TYPE,
     [ 3 ]     = 0,
};
initializes expr_type expr_x[0] = 0; expr_type expr_x[ 1 ] = A_TYPE; expr_type expr_x[ 2 ]  = B_TYPE; expr_type expr_x[ 3 ] = 0;
0
 
LVL 13

Author Comment

by:ispaleny
ID: 17824418
It is in header files. I am able to handle expr_x:
      static enum expr_type expr_x[MAX_INDEX] ={0,A_TYPE,B_TYPE,0}

But what should I do with x_type_value in Visual Studio? Is the hardcoded order of values necessary?
0
 
LVL 13

Author Comment

by:ispaleny
ID: 17851937
ozo,

I verified the functionality and replaced it by a very long list of mixed zeroes and values.  

Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question