Question

I have come across some old code written in old non-ansi C a long time ago and I am trying to get my head around the function definition.

I can understand the end result but I want to fully understand the code style..

Use:

ok = ElementFn(lifestyleRollupContribution)( gr, nr, cnt, id, prj, k, f, rnd, base );

Function definition:

Private Logical ElementFn(lifestyleRollupContribution)
(
    Real*   gross,
    Real*   net,
    Const Real* contribution,
    Const Date* investment,
    Const Date* projection,
    Const PCode* key,
    Const PCode* fund,
    Const PCode* inv_prd_round,
    Const Date* inv_prd_base_date
)
{
// stuff
}

So in this example I can see a function called ElementFN that returns a 'Logical' and that has a number of parameters. What I don't get is what is (lifestyleRollupContribution) it is used only twice where you see it.. but what is it doing? what does it denote - nothing I recognise. I have seen references to Kernighan and Ritchie style function declaration but this doesn't appear to be that?

Was it helpful?

Solution

In modern C, that could only be a macro. Example:

#define ElementFn(name) function_ ## name
#define Private 
typedef float Logical;
typedef float Real;

Private Logical ElementFn(lifestyleRollupContribution)(
    Real   gross,
    Real   net
) {
    return 2.0f;
}

int main(void) {
    printf("%f", ElementFn(lifestyleRollupContribution)(3.05f, 42.0f));
    return 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top