Book a Demo

Author Topic: extern declaration of functions in C-Header Files  (Read 6460 times)

Daimonion

  • EA Novice
  • *
  • Posts: 5
  • Karma: +1/-0
    • View Profile
extern declaration of functions in C-Header Files
« on: April 27, 2016, 09:03:36 pm »
Hi

For my actual project i want to use enterprise architect for designing my code architecture. I'm programming in C on an embedded controller (Microchip dsPIC33E 16Bit Controller)
In my architecture i develop with EA i'm using class diagramms and class- as well as interface structures.
And these interface structure  shall be exported via code generation as C-header files. Till now i managed to get exported anonymous typedef structures, datatypes, comments and all include specs. But i doesn't get it to work that the desired "extern" declaration is exported

Every operation is exported without the "extern" declaration.

My Question is. Which option/field/tag i have to set that the code generation generates the "extern" declaration? (For anonymous structures i had to create customer tags "anonymous" and "typedef" ans set it to true)

https://goo.gl/photos/RTCejAvF6AF4iXo97

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: extern declaration of functions in C-Header Files
« Reply #1 on: April 28, 2016, 02:39:14 am »
Hello, and welcome to the forum.

Please note that like most of us here I'm just another user, not a Sparx employee.

I had a quick look through the code generation templates for C, and it seems EA doesn't generate the "extern" keyword at all. I tried importing a header file with an extern declaration in it, and EA stored that as a tagged value "extern" with value "true" on the operation -- but it doesn't generate it back out again.

So it looks like you're going to have to go into the code generation templates. It's a bit fiddly, but not too hard.

Have a look at the Operation Declaration template. I'd put something like
Code: [Select]
%opTag:"extern" ? "extern" : ""%in there before %opReturnType%.

Haven't tested it, mind. But something along those lines ought to do it.
The corresponding help page is here.

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

Daimonion

  • EA Novice
  • *
  • Posts: 5
  • Karma: +1/-0
    • View Profile
Re: extern declaration of functions in C-Header Files
« Reply #2 on: April 28, 2016, 04:45:14 pm »
Thnanks for your respond and the hint to the operation template.

I thought that i couldn't change the behaviour of the list macro. now i know that they just call another template where i can change the output. *thumbsUp* Your Example works fine here and i even got it more complex that i can write an extern stereotype!

Regards
Daimonion