-1

``I have a requirement that the function call will have different names but all of them should refer to the same definition while executing. For example, i have a function calls like

UINT8 vsignal;UINT8 vsignal1;void Read_Message1_Signal1(&vSignal);void Read_Message2_Signal2(&vSignal1);

but this should be linked to

void Read_Message_Signal(UINT8 *signal){}

which is already implemented and compiled as a dll and should be linked to the different calls as those calls may vary based on the input.

Can anyone help me how to achieve this requirement?

Ambuja
  • 197
  • 1
  • 12
  • 2
    Hard to answer this question because you didn't really ask anything specific. The answer to "how do you achieve this?" is to just *do it*. You seem to understand how to call functions, so what more do you need? – tenfour Sep 20 '11 at 11:51
  • @tenour: thanks for the reply but here i want wrap the many function calls into a single function definition. And, here the argument type will vary based on the pointer to a structure. Here, whatever i have given is simplest example. – Ambuja Sep 21 '11 at 03:12

3 Answers3

1
void Read_Message1_Signal1(&vSignal)
{
    Read_Message_Signal(&vSignal);  // or whatever
}

and repeat for your other function names, perhaps with a custom code generator.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • :thanks for the reply and this what i thought of when there are no changes in the type of the data structure passed as an argument. I have one more situation like struct{UINT8 sig1; UINT16 sig2, UINT8 sig3}Message1; Message1 varMsg1; void Read_Message1(&varMsg1) struct{UINT8 sig5; UINT16 sig6, UINT8 sig7}Message2; Message1 varMsg2;void Read_Message2(&varMsg2) . how to do this? – Ambuja Sep 21 '11 at 03:14
1

Is there some reason you can't just write your own wrapper?

void Read_Message1_Signal1(&vSignal)
{
    Read_Message_Signal(vSignal);
}

void Read_Message2_Signal2(&vSignal)
{
    Read_Message_Signal(vSignal);
}

You can autogenerate these with a macro if there are a lot of them.

Vicky
  • 12,934
  • 4
  • 46
  • 54
  • thanks for the reply and this what i thought of when there are no changes in the type of the data structure passed as an argument. I have one more situation like struct{UINT8 sig1; UINT16 sig2, UINT8 sig3}Message1; Message1 varMsg1; void Read_Message1(&varMsg1) struct{UINT8 sig5; UINT16 sig6, UINT8 sig7}Message2; Message1 varMsg2;void Read_Message2(&varMsg2) . how to do this? – Ambuja Sep 21 '11 at 03:18
  • It looks like you're getting mixed up between the TYPES of your structure members and the NAMES you happen to be giving them. In this example Message1 and Message2 are compatible structures, so you can use the same structure type definition for each. – Vicky Sep 21 '11 at 11:11
1

You can use the preprocessor for that:

#define Read_Message1_Signal1(x) Read_Message_Signal(x)
#define Read_Message2_Signal2(x) Read_Message_Signal(x)

Or rethink your API, because this seems strange to me...

Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87
  • This doesn't actually create functions, of course, so it may lead to linker problems (depending on the application). – Fred Foo Sep 20 '11 at 11:54
  • @larsmans, well, it is not clear what the OP exactly needs, so this may be of help to he or she. – Diego Sevilla Sep 20 '11 at 11:55
  • @Diego Sevilla: i tried in this way 'larsmans' was correct it leads to many linker errors. I have one more condition here that even data structure of argument will be different for all the calling functions like: struct{UINT8 sig1; UINT16 sig2, UINT8 sig3}Message1; Message1 varMsg1; void Read_Message1(&varMsg1) struct{UINT8 sig5; UINT16 sig6, UINT8 sig7}Message2; Message1 varMsg2;void Read_Message2(&varMsg2) . how to do this? – Ambuja Sep 21 '11 at 03:20