Solved

Strange enumeration in GNUC syntax

Posted on 2006-10-27
3
242 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
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements 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.

810 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