einsteinjunior wrote:
Hi,
You should know what the extern keyword functions when applied to functions.
When a function is declared without the keyword ,and object code is generated for the source file,the function is mangled,that is an underscore is added at the end.So a function such as:
myfunct()
will become:
_myfunc()
If you look at the nasm code you will see that nasm mangles the c functions when called from within it.So to call our function without the extern keyword in nams we will need to do it this way:
call __myfunc();notice the double underscore
double underscore are usually reserved for compiler specific operations,
so you use extern to unmangle the functions so you can call then like this from nasm:
call _myfunc()
No,
No,
No!The prepending of an underscore is
not name mangling. Name mangling is
only present in C++, and consists of encoding the namespace, template types and parameters of a function to avoid conflicts with overloading (so you end up with, for 'main()', '_Z4mainv'.)
This only affects C++ code, not C code, and uses 'extern "C"', which is completely different to 'extern' (without the "C").Quote:
Thanks for the fast reply, dont see how it can "help the programmer determine easily where the definition of a function (does not) reside" since its just a keyword or did i miss something?
Yes, it's just a keyword, and yes, it does nothing, however if one sees a function prototype with "extern" before it, one can deduce that the definition of that function is
not in the current file. It is elsewhere. This may (or may not) save you time.
Quote:
this was another thing i thought about asking, why the built-in functions and in the headers files they use __
Built in functions tend to use preceding underscores so as not to pollute the namespace.
Cheers,
James