Book a Demo

Author Topic: Declaring const arrays in a class  (Read 7513 times)

HansChandra

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Declaring const arrays in a class
« on: May 01, 2013, 10:41:16 pm »
Hello,
How does one declare and initialize single and multidimensional arrays in EA/UML?   The ultimate objective would be to generate code from a class diagram that has the array defined in it.

Foe example the generated code for a 3x4 array, aaray1[3][4] should look something like:

const int array1
{
  {1,2,3,4},
  {5,6,7,8},
  {9,10,11,12}
};

I am from the C world and new to EA  and UML... please help!

Thanks,
Hans.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Declaring const arrays in a class
« Reply #1 on: May 01, 2013, 11:56:00 pm »
Hello,

the easiest way to find out is to write the code in C and import it.

It's always a good idea to use reverse engineering to see what EA makes with your various language constructs. If you wish you can do it the opposite direction.

Code Engineering, Import source from Code, C.

With C there is often some surprise and you have to play try and error.

Property:
- Const
- Initial value init value
- Container Type contains the dimension [3][4]

If you want to do round trip engineering give it a try in both direction. As I said: There are sometimes surprises. I managed most/all surprises. But it takes some time until you get familiar with the peculiarities.

Good luck,

Helmut



Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

HansChandra

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Declaring const arrays in a class
« Reply #2 on: May 02, 2013, 01:25:57 am »
Helmut,
Thanks!   The import worked.  The Array attribute had the initial values and the container type had the proper dimensions [3][4]. However when I generated code from the model after the import, the code did not have the initial values assigned. All I got was the declaration : const int Array1[3][4];

Did you run into this issue?

Thanks in advance!
Hans.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Declaring const arrays in a class
« Reply #3 on: May 02, 2013, 02:18:51 am »
Hello Hans,

which EA release to you used? Was it privat or public? Have you checked both *.h and *.c.

I tried 1007 and it didn't work.

Sometimes it works with a slightly different notation. C offers more than one way to express something. If reverse engineering works and forward generation don't works you can adopt C-Code generation by the EA template based code generation. There you can do almost everything.

For reverse engineering there is no such feature.

In 10 you may define your own language. I think it's not that easy to do this for C.

May be write a bug report or use another EA release (9.35,10.07,..).

Best regards,

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

HansChandra

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Declaring const arrays in a class
« Reply #4 on: May 02, 2013, 03:15:19 am »
Hello Helmut,
I am using 1004, Yes I had checked the *.h and *.c file.  Looks like it is a bug.  I will try with an older version if we have it here. I'll also try the template route.

Thanks for the tip.

Hans.

HansChandra

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Declaring const arrays in a class
« Reply #5 on: May 02, 2013, 03:55:06 am »
Hello Helmut,
Success! Like you said you can achieve almost anything with the templates.  I modified the Attribute template and got it to work with forward engineering.
 8-)
Thanks again!
Hans.