I know that extern C means the function should be compiled in C style however what does just extern function_datatype functionname mean?
extern void sharelog(const char *rem_host, const char *username,
const char *, const char *,
const char *, const char *);
What does extern without "C" me开发者_开发百科an?
Also, in almost every program's header files i see something along the lines of
void sharelog(const char *rem_host, const char *username,
const char *, const char *,
const char *, const char *);
Why declare the function again if it's been done in the .c/.cpp file? It's also sometimes declared without it's argument just
int Function;
Also, some functions can be written like this:
int CSomething::Somefunction() const
Why add const after the function?
I've also stumbled across functions which have these mysterious dots
void function(int prio, const char *fmt, ...)
There were a lot of other things i also wanted to ask, however it seems i already asked enough. I know some of you will probably say to go learn C/C++, however believe me, these stuff are not discussed for beginners.
- How does extern work in c++?
- Why does C++ need a separate header file?
- const CFoo &bar() const and What's the difference between a const member function and a non-const member function?
- What's the correct term for the '...' token?
The extern
without "C"
comes from pre-C++ times when you needed a way to tell the C compiler that a function is available "somewhere" and it should allow the linker to figure it out.
The declaration with extern
allowed the compiler to add the function to the list of known names even if it couldn't resolve the address.
精彩评论