Solved

Strange enumeration in GNUC syntax

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

Industry Leaders: 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

Title # Comments Views Activity
C Language combined operators 28 135
Problem to save 10 177
Problem to scan all sheets 3 130
Setting variables in a stored procedure 5 74
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

734 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