| |||
| Home > Components > Behavior sections | |||
Component descriptions can comprise multiple named behavior sections that specify the behavior of the component model. Behaviors can be considered to be similar to a function.
Behaviors of components always have a name and can also have an optional list of formal parameters and an optional return type as shown in Example 2.17:
Example 2.17. init behavior
component MyComponent
{
// this behavior does not have parameters and has no return type
behavior init
{
// initialize component
}
// this behavior has two parameters
// the syntax is C-like
behavior setPixel(uint32_t x, uint32_t y)
{
}
// this behavior has a parameter and return a value of type 'bool'
// the syntax for return types differs from C
behavior isValidAddress(uint32_t address): bool
{
return address < memorySize;
}
}
The C/C++ code in a behavior body can directly access all resources declared in the resource section.