开发者

Can you explain what extern means and some other things? [closed]

开发者 https://www.devze.com 2023-03-08 04:04 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.


  1. How does extern work in c++?
  2. Why does C++ need a separate header file?
  3. const CFoo &bar() const and What's the difference between a const member function and a non-const member function?
  4. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消