Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: hds on April 02, 2012, 05:44:26 am

Title: How to modelling C- #defines in UML?
Post by: hds on April 02, 2012, 05:44:26 am
Hi All,

how can I design ANSI-C #defines like:
#define PARAM_A  1
#define PARAM_B  2
....

I think these should be attributes in a class?! But the code generator builds variables.

Is there a way to get those #defines ???

best regards,
hds
Title: Re: How to modelling C- #defines in UML?
Post by: g.makulik on April 02, 2012, 08:14:39 am
Hi,

I don't think its possible that way, because #define is a preprocessor feature.
Additionally I think you should use enumerations or static const value definitions instead of #define to represent constants (as recommended in most coding conventions), these will be modellable.

HTH
Günther
Title: Re: How to modelling C- #defines in UML?
Post by: hds on April 04, 2012, 04:06:58 am
Hi,

I don't think so.
Do you really make a const var for defines like:
UPPER_LIMIT
LOWER_LIMT
THRESHOLD_X
PARAM_A_ID
PARAM_B_ID
PARAM_C_ID
SET
RESET

I don't know ????
With those methods you get unreadable code!
Why is EA unable to generate #defines?
Title: Re: How to modelling C- #defines in UML?
Post by: woodz on April 04, 2012, 04:57:42 am
Hello,

you can type them into source code window (generate your code previously). EA will keep them while sync forward/backward.
Note that the idea of UML actually isn't dependent on any specific programming language.
Have you been thinking of tagged values? I am not familiar with them but they should be very powerful by aiming on code generation.

Greetings
woodz
Title: Re: How to modelling C- #defines in UML?
Post by: g.makulik on April 04, 2012, 07:28:55 am
Quote
Hi,

I don't think so.
Do you really make a const var for defines like:
UPPER_LIMIT
LOWER_LIMT
THRESHOLD_X
PARAM_A_ID
PARAM_B_ID
PARAM_C_ID
SET
RESET

I don't know ????
With those methods you get unreadable code!
Why is EA unable to generate #defines?
Why code using const var defs should be unreadable?? What's the difference? You'll get even more safe code, because you need to specify exact types. OK, I'm more used to programming in C++ than in C, but our coding rules say to avoid #defines like the plague ...

On very limited targets or with very tight performance restrictions there might be at least one point, where a (numeric) #define would behave better than a variable, because the direct loading of a register with a value could be more efficient than fetching it from an address.

Günther
Title: Re: How to modelling C- #defines in UML?
Post by: Makulik on April 04, 2012, 05:47:21 pm
BTW, enumerations will do the job for numeric constants very well. Even better than static const vars when you want to use the constants in switch/case statements.

Günther
Title: Re: How to modelling C- #defines in UML?
Post by: hds on April 05, 2012, 05:27:33 am
Hi all,

I found what I need:
A attribute needs a tagged value named "define" = true. That's all!

I also try to use enums more often, but const vars in compact embedded systems seems to be a waste of flash memory.

Bye
hds
Title: Re: How to modelling C- #defines in UML?
Post by: g.makulik on April 05, 2012, 06:04:02 am
Quote
Hi all,

... but const vars in compact embedded systems seems to be a waste of flash memory.
I totally agree for (integer) numeric values (mentioned that), but #defines for const char* or FP literals may behave even worse for that concern. Depends on the specific compiler optimization that literals might be compared and expanded uniquely.

Best regards,
Günther
Title: Re: How to modelling C- #defines in UML?
Post by: Eve on April 13, 2012, 08:33:22 am
For reverse engineering see also Tools | Options | C | Import #define Constants