0

I have a structure that I used to populate Class Structures with values:

MyType structMy[] =
{
  { START,  INTEGER_TYPE, 3, (void *)&classStart->statusStart.set    },
  { STABLE, CHAR_TYPE,    5, (void *)&classtStable->statusStable.set },
  { STOP,   DOUBLE_TYPE,  1, (void *)&classStop->statusStop.set      }
}

But for testing and validation I want to add test cases to the structure: some values which depend on the defined data type per line and number of values.

But because of the structure setup and 1 value or an array, I think I need a (void*). But the compiler doesn't like it. What can I do to write an array into a structure where data types can change?

MyType structMy[] =
{
  { START,  INTEGER_TYPE, 3,  (void*){0, 1, 2}                 },
  { STABLE, CHAR_TYPE,    5,  (void*){'A', 'B', 'C', 'D', 'E'} },
  { STOP,   DOUBLE_TYPE,  1,  (void*){2.4}                     }
}
1
  • 1
    Is this what Google translate does? Commented Sep 20, 2011 at 18:20

2 Answers 2

1

The compiler wants pointers there, so try declaring the data elsewhere:

int is[] = {0, 1, 2};
char cs[] = {'A', 'B', 'C', 'D', 'E'};
double ds[] = {2.4};

MyType structMy[] =
{
     {START, INTEGER_TYPE, 3,  (void*)is },
     {STABLE, CHAR_TYPE, 5,  (void*)cs },
     {STOP, DOUBLE_TYPE, 1,  (void*)ds }
}
Sign up to request clarification or add additional context in comments.

Comments

0

By telling the compiler what type to expect, it can be done like this:

MyType structMy[] =
{
   { START,  INTEGER_TYPE, 3,  (void*)(int[]){0, 1, 2}                  },
   { STABLE, CHAR_TYPE,    5,  (void*)(char[]){'A', 'B', 'C', 'D', 'E'} },
   { STOP,   DOUBLE_TYPE,  1,  (void*)(double[]){2.4}                   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.