Solved

Strange enumeration in GNUC syntax

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is string constant address ? 10 192
C hashtable library 3 83
Setting nameservers after res_init fails doing res_query 2 86
outlook office 365 8 84
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…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

867 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

19 Experts available now in Live!

Get 1:1 Help Now