Reputation: 21
I have two modules written in C11 in my project: 'test1.c' and 'test2.c'. Module 'test1.c':
int FunctionWithVeryLONGLONGLONGLONGName(char* data)
{
// do something
}
Module 'test2.c':
extern int FunctionWithVeryLONGLONGLONGLONGName(char* data);
int main(void)
{
char data[ DATA_LEN + 1 ] = { "test_data" };
FunctionWithVeryLONGLONGLONGLONGName(data);
return 0;
}
I want to use short name for function 'FunctionWithVeryLONGLONGLONGLONGName' in module 'test2.c' without modification of module 'test1.c'. F.e., something like this:
FuncWithShortName(data);
I try to do:
extern int FunctionWithVeryLONGLONGLONGLONGName(char* data);
typedef int FunctionWithVeryLONGLONGLONGLONGName(char* data);
FunctionWithVeryLONGLONGLONGLONGName FuncWithShortName;
int main(void)
{
char data[ DATA_LEN + 1 ] = { "test_data" };
FuncWithShortName(data);
return 0;
}
But compiler gave an error: "Definition of function FunctionWithVeryLONGLONGLONGLONGNamerequires parentheses." What did I do wrong ?
Upvotes: 0
Views: 64
Reputation: 72431
typedef
creates a type alias, not a function alias or anything else.
You could get a sort of function alias by defining a file-local pointer to function:
static int (*const FuncWithShortName)(char*) =
FuncWithVeryLONGLONGLONGLONGName;
Upvotes: 2