Extern

How do i use extern to call a function?

I tried this and i chashed:

main.cpp
1
2
3
4
5
6
7
  [..]
  void a(int,int);
  
  int main()
  {
  a(0,0);
  }


other.cpp
1
2
  extern a(int,int);
  a(0,1);
You don't need to use extern for a function call. all that you need is a function prototype of a() inside other.cpp. The linker will figure out where a() is defined when you build your project.

Generally speaking, extern is used for data objects, prototype are used for functions.
Last edited on
Topic archived. No new replies allowed.