0

Basically, I have a FileA.c:

//FIleA.c
void inline something()
{  
 //short code here

}
void inline another()
{ 
  //short code here
}

Now I want to call these inline functions in another file main.c without using a header file. How should I declare the prototypes of these functions in main.c?

//main.c
#include "FileA.c"
void something(); 
void another();
// or ???

int main()
{
 something();
 another();
 something();
 another();

 return 0;

}
KurodaTsubasa
  • 25
  • 2
  • 5

1 Answers1

1

This answer actually suggests that there's no possible use case for defining inline functions in another .c file in this way.

On the other hand, if you #include "FileA.c" in your main file anyway, then you don't need to do anything, because you are using a header file (ending the name of an included file with .c doesn't change what it fundamentally is, it just confuses people reading your code).

Community
  • 1
  • 1
Alex Celeste
  • 12,824
  • 10
  • 46
  • 89
  • If I remove my prototypes in main.c. It won't compile. (XCode, Linker error) – KurodaTsubasa May 01 '13 at 02:40
  • As a practical note, if you're using Xcode, the compiler will ignore your `inline` declarations anyway. Firstly because it knows better than you when to inline functions, and secondly because LLVM can inline functions at link-time and doesn't need to use this old-fashioned mechanism at all. Use the functions normally and they will be inlined if it's appropriate. – Alex Celeste May 01 '13 at 20:43