Solved

Strange enumeration in GNUC syntax

Posted on 2006-10-27
3
222 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
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
ozo,

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

Thank you.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now