0

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Jon H
  • 1,061
  • 4
  • 13
  • 32

1 Answers1

6

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;
}
Alex Watson
  • 519
  • 3
  • 13
  • I think you may be right I found this '#define ElementFn(x) EF##x' it is nasty code though! I am sure it made sense when it was being written decades ago thought! I would never have considered a Macro; mainly because I have never had cause to use them! and this one (if it is) has about 200 lines of code in it!!! – Jon H Nov 22 '13 at 10:45
  • It is a Macro - but I still don't know how it is used fully. Thanks for pointing me in the right direction. – Jon H Nov 22 '13 at 14:51
  • Does your compiler supports expanding of the macros? In my opinion it's very helpful. Check the following question for details in gcc: http://stackoverflow.com/questions/985403/seeing-expanded-c-macros – Lazureus Jun 28 '14 at 20:49