void initStructT(struct_td * pStruct, long value);
we need the following local variable:
Note, that we have to initialize each structure or array member separately.
Now we can use the declared and initialized variables as function parameters:
Declaration:
myChar char[10]
Initialization:
myChar "Hello!"
For number arrays we can use curly braces, for example:
Declaration:
myArray int[10]
Initialization:
myArray {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
void f(int *p);
and we declare variable:
param1 int *
and then 'initialize' it like:
*param1 10 // DON'T DO THIS!!!
then param1 will contain uninitialized address, depending on
previous stack content. Symptoms: test will sometimes succeed,
sometimes fail with error. Proper approach:Declaration:
param1 int
Initialization:
param1 10
Function parameter:
¶m1
iCounter is initialized to
value 10:
Warning: If we define type of a variable, it means a declaration of a local variable. If it has the same name as a global variable, the global variable is hidden!
"<moduleName>#"<varName>,,<downloadFileName>
where:
moduleName - name of the C source file, which
contains the variable (optional)varName - name of the variabledownloadFileName - name of the download file, where the variable is located
"main.c#"iCounter,,executable.elf
iCounter,,executable.elf
When we use such variable in expressions, the download file name
is valid for whole expression, so we have to specify it at the
end of expression, for example:
iCounter == 3,,executable.elf
<functionName>##<functionStaticVarName>
where:
functionName - name of the function, which
contains static variablefunctionStaticVarName - name of the static
variable inside the function
myFunction##myStaticVar
decltype(<functionName>##N)
decltype(*<functionName>##N)[K]
decltype_ref(<functionName>##N)
where:
Examples:
void myFunction(MyStruct a)we can use the following type instead of type
MyStruct:
decltype(myFunction##1)
otherFunction(MyType *ptr)and we want to create an array of 5 elements of type
MyType to
be used as a pointer parameter, we can write:
decltype(*myFunction##1)[5]Note that type of the first function parameter is
MyType
*. We have to dereference it to get
type MyType.
void f(int n1, int * pn2, int & rn3)we can get parameter types using one of the following:
| Syntax | Returned type | Description |
|---|---|---|
| decltype(f##1) | int | type of 1st parameter (n1) |
| decltype(f##2) | int * | type of 2nd parameter (pn2) |
| decltype(*f##2) | int | type of pointer |
| decltype(*f##2)[3] | int[3] | declares array to be used as the first parameter |
| decltype(f##3) | int & | type of param3 (rn3) |
| decltype_ref(f##3) | int | referenced type of param3 (rn3) |