You are on page 1of 1

linkedin.

com/in/amrmsamy

One of most t he most popul ar quest ions in embedded Sy st ems int er views

St at i c v s Ex t er n

External Linkage
Internal Linkage

static extern

functions variables functions variables

global variables

1. limits the scope to 1. The extern keyword 1. An external variable


that function to only local global in fact does nothing can be declared many
its object file. when applied to times but can be
2. Static functions is function declaration. initialized only once.
only visible in its 1. Extend the life time 1. like functions it limits This because all 2. The variables declared
object file. to that variable until the scope to that function declarations as extern are not
3. In effect, static the whole program. variable to only its have an implicit allocated any memory.
undoes the work of 2. Static Variables are object file instead of extern applied. It is only declaration
the implicit extern. allocated memory in the whole program. 2. A variable or are intended to specify
data segment, not 2. Static functions is function can be that the variable is
stack segment. only visible in its declared any number define elsewhere in
3. Static Variables are object file of times, but it can the program
initialized as Zero if be define only once.
not initialized.
4. Static variables can
only be initialized
By using 'exter n' , you are telling the compiler that
using constant whatever follows it will be found at link time
literals.
5. Remmber that the
normal or auto
variable is destroyed Mor e about ext er n :
when a function call
- When we write extern : no memory is
where the variable
allocated. Only property of variable is
was declared is over.
anounced.
- multiple declarations of extern variable
is allowed within the file.
- extern variable says to compiler " go
outside my scope and you will find the
definition of the variable that I
declared " .
- Compiler belives that whatever that
extern variable said is true and
produce no error. Linker throws an
error when it finds no such variable
exists.
- When an extern variable is initialized ,
then memory for this is allocated and
it will be considered defined.

You might also like