extern methods

B

Blue Ocean

In standard C, what is the effect of declaring a method extern. In
what cases should I use this? Programs that I've compiled with more
than one source files and multiple headers still seem to work even
when a method in one file calls a method in another, even though I've
yet to declare any method extern. Why?
 
A

Artie Gold

Blue said:
In standard C, what is the effect of declaring a method extern. In
what cases should I use this? Programs that I've compiled with more
than one source files and multiple headers still seem to work even
when a method in one file calls a method in another, even though I've
yet to declare any method extern. Why?

There are no methods in C; they're *functions*.

Functions have external linkage by default in C, making the keyword
redundant.

HTH,
--ag
 
J

jacob navia

Blue Ocean said:
In standard C, what is the effect of declaring a method extern. In
what cases should I use this? Programs that I've compiled with more
than one source files and multiple headers still seem to work even
when a method in one file calls a method in another, even though I've
yet to declare any method extern. Why?

Functions are extern by default. "Methods" exist (maybe) in C++
but not in C. In C "methods" are not associated to a data packet
and called just "Functions".

As you may have noticed, in C functions do not receive an
implicit object pointer (the "this" argument).

So they aren't methods. They are by default extern, i.e. visible
in other modules. If you do not want them to be visible
you define them as static, like this

static int myFn(int someArg)
{}

This means "myFn" will not be visible outside the current unit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top