I got a bunch of code, that I should analyze and prepare for import it to a new project. Often there are the following patterns:
typedef struct t_Substruct
{
/* some elements */
} ts;
typedef struct t_Superstruct
{
/* some elements */
ts substruct;
/* some more elements */
} tS;
void funct1(const tS * const i_pS, tS * const o_pS)
{ /* do some complicated calculations and transformations */ }
void funct2(const ts * const i_ps, tS * const o_pS)
{ /* do some complicated calculations and transformations */ }
void funct3(const tS * const i_ps, ts * const o_ps)
{ /* do some complicated calculations and transformations */ }
In general there is reading from the i_ parameters and writing to the o_ parameters. Now there might be calls like:
void some_funct()
{
tS my_struct = {0};
/* do some stuff */
funct1(&my_struct,&my_struct);
funct2(&my_struct.substruct, &my_struct);
funct3(&my_struct, &my_struct.substruct);
}
Im not sure about the possible pitfalls to such functions and calling context:
- Are such declarations or calls in context of const correctness allowed with regards to language constraints and/or undefined behavior?
- Is it allowed to change one object, that is referenced protected and not protected in the same function?
- I know there are some problems with accessing / modifying the same variable multiple times between, sequence points (although I am not perfectly sure if I understand the sequence point thing totally). Does this or similar issues apply here, and in which way?
- If not undefined behavior, is there any other typical problem which reduces portability in the above situation?
- If there are problems, what would be a good (safe and if possible with as little overhead as possible) general pattern to allow those calls, so that such issues might not happen every other line?
I have to implement in C90, but if there are issues in porting to other C incarnations, regarding the above, this is also important for me.
Thank you in advance.