top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is internal linking and external linking in c++?

+2 votes
What is internal linking and external linking in c++?
posted Mar 26, 2014 by Mohammad

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

When you write an implementation file (.cpp or .cxx or something else) your compiler generates a translation unit. This is the object file from your implementation file plus all the headers you *#include*d in it.

Internal linkage refers to everything only in scope of a translation unit. External linkage refers to things that exist beyond a particular translation unit. In other words, accessable through the whole program, which is the combination of all translation units (or object files).

Example: test.cpp

#include <iostream>
using namespace std;

extern const int max;
extern int n;
static float z = 0.0;

void f(int i)
    static int nCall = 0;
    int a;
    a = max * z;
    cout << "f() called " << nCall << " times." << endl;

max is declared to have external linkage. A matching definition for max(with external linkage) must appear in some file. (As in test.cpp)
n is declared to have external linkage.
z is defined as a global variable with internal linkage.
The definition of nCall specifies nCall to be a variable that retains its value across calls to function f(). Unlike local variables with the default auto storage class, nCall will be initialized only once at the start of the program and not once for each invocation of f(). The storage class specifier static affects the lifetime of the local variable and not its scope.

answer Mar 26, 2014 by Amit Kumar Pandey
Similar Questions
0 votes

I am new to apache, so forgive me if this is a beginner questions.

I am trying to redirect request to apache based on the IP address. Depending on where the request originates from, the request will either have a external or internal IP address. External will be redirected to the external site, internal will be redirected to the internal site.

Request to will be evaluated based on the IP address. Then redirected to either or . I am able to accomplish this with the following.

 RewriteCond %{REMOTE_ADDR} ^ 
 RewriteRule ^(.*)$ [R=301,L] 
 RewriteCond %{REMOTE_ADDR} ^ 
 RewriteRule ^(.*)$ [R=301,L] 

The problem I am running into is that this is in a loop. Every request will be evaluated and redirected. If possible, I need a way to redirect once, then let other request ( or )not be evaluated and then redirected

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.