---------------
// file1.cpp:
    int x = 1;
    int f() { /* robi co */ }

// file2.cpp:
    extern int x;
    int f();
    void g() { x = f(); }
---------------
// file1.cpp:
    int x = 1;
    int b = 1;
    extern int c;

// file2.cpp:
    int x; // oznacza int x = 0;
    extern double b;
    extern int c;
---------------
// file1.cpp:
int g() { return f()+7; } // bd: funkcja f() nie jest jeszcze zadeklarowana
int f() { return x; }     // bd: zmienna x nie jest jeszcze zadeklarowana
int x;
---------------
static int x1 = 1;   // wizanie wewntrzne: nazwa niedostpna w innych jednostkach translacji
const char x2 = 'a'; // wizanie wewntrzne: nazwa niedostpna w innych jednostkach translacji
---------------
int x1 = 1;                 // wizanie zewntrzne: nazwa dostpna w innych jednostkach translacji
extern const char x2 = 'a'; // wizanie zewntrzne: nazwa dostpna w innych jednostkach translacji
---------------
// file1.cpp:
    inline int f(int i) { return i; }

// file2.cpp:
    inline int f(int i) { return i+1; }
---------------
// file1.cpp:
    extern inline int g(int i);
    int h(int i) { return g(i); } // bd: funkcja g() jest niezdefiniowana w tej jednostce translacji

// file2.cpp:
    extern inline int g(int i) { return i+1; }
    //...
---------------
// h.h:
    inline int next(int i) { return i+1; }

// file1.cpp:
    #include "h.h"
    int h(int i) { return next(i); } // w porzdku

// file2.cpp:
    #include "h.h"
    //...
---------------
// file1.cpp:
    using T = int;
    const int x = 7;
    constexpr T c2 = x+1;

// file2.cpp:
    using T = double;
    const int x = 8;
    constexpr T c2 = x+9;
---------------
// file1.cpp:
extern const int a = 77;

// file2.cpp:
    extern const int a;

    void g()
    {
        cout << a << '\n';
    }
---------------
// file 1.cpp:
    namespace {
        class X { /*...*/ };
        void f();
        int i;
        //...
}

// file2.cpp:
    class X { /*...*/ };
    void f();
    int i;
    //...
---------------
#include "do_doczenia"
---------------
#include <iostream>   // z katalogu standardowego
#include "myheader.h" // z biecego katalogu
---------------
#include < iostream > // nagwek <iostream> nie zostanie znaleziony
---------------
// file1.cpp:
    struct S { int a; char b; };
    void f(S*);

// file2.cpp:
    struct S { int a; char b; };
    void f(S*p) { /*...*/ }
---------------
// s.h:
    struct S { int a; char b; };
    void f(S*);

// file1.cpp:
    #include "s.h"
    // uycie funkcji f()

// file2.cpp:
    #include "s.h"
    void f(S*p) { /*...*/ }
---------------
// file1.cpp:
    struct S1 { int a; char b; };

    struct S1 { int a; char b; }; // bd: podwjna definicja
---------------
// file1.cpp:
    struct S2 { int a; char b; };

// file2.cpp:
    struct S2 { int a; char bb; }; // bd
---------------
// file1.cpp:
    typedef int X;
    struct S3 { X a; char b; };

// file2.cpp:
    typedef char X;
    struct S3 { X a; char b; }; // bd
---------------
// s.h:
    struct S { Point a; char b; };

// file1.cpp:
    #define Point int
    #include "s.h"
    //...

// file2.cpp:
    class Point { /*...*/ };
    #include "s.h"
    //...
---------------
#ifdef __cplusplus // tylko dla kompilatorw C++ (15.2.5)
namespace std {    // biblioteka standardowa jest zdefiniowana w przestrzeni nazw std (4.1.2)
extern "C" {       // funkcje stdio maj czenie C (15.2.5)
#endif
    /*...*/
    int printf(const char*, ...);
    /*...*/
#ifdef __cplusplus
}
}
//...
using std::printf; // udostpnienie printf w globalnej przestrzeni nazw
//...
#endif
---------------
extern "C" char* strcpy(char*, const char*);
---------------
extern char*strcpy(char*, const char*);
---------------
extern "C" int f();

int g()
{
    return f(1); // bd: nie jest oczekiwany jakikolwiek argument
}
---------------
extern "C" {
    char*strcpy(char*, const char*);
    int strcmp(const char*, const char*);
    int strlen(const char*);
    //...
}
---------------
extern "C" {
#include <string.h>
}
---------------
#ifdef __cplusplus
extern "C" {
#endif
    char*strcpy(char*, const char*);
    int strcmp(const char*, const char*);
    int strlen(const char*);
    //...
#ifdef __cplusplus
}
#endif
---------------
extern "C" {       // dowolna deklaracja, na przykad:
    int g1;        // definicja
    extern int g2; // deklaracja, nie definicja
}
---------------
extern "C" int g3;     // deklaracja, nie definicja
extern "C" { int g4; } // definicja
---------------
#include<cstdio>
void f()
{
    std::printf("Witaj, "); // OK
    printf("wiecie!\n");   // bd: brak globalnej funkcji printf()
}
---------------
typedef int (*FT)(const void*, const void*);                // FT ma czenie C++

extern "C" {
    typedef int (*CFT)(const void*, const void*);           // CFT ma czenie C
    void qsort(void*p, size_t n, size_t sz, CFT cmp);       // cmp ma czenie C
}

void isort(void*p, size_t n, size_t sz, FT cmp);            // cmp ma czenie C++
void xsort(void*p, size_t n, size_t sz, CFT cmp);           // cmp ma czenie C
extern "C" void ysort(void*p, size_t n, size_t sz, FT cmp); // cmp ma czenie C++

int compare(const void*, const void*);                      // compare() ma czenie C++
extern "C" int ccmp(const void*, const void*);              // ccmp() ma czenie C

void f(char*v, int sz)
{
    qsort(v,sz,1,&compare); // bd
    qsort(v,sz,1,&ccmp);    // OK

    isort(v,sz,1,&compare); // OK
    isort(v,sz,1,&ccmp);    // bd
}
---------------
// dc.h:

#include <map>
#include<string>
#include<iostream>

namespace Parser {
    double expr(bool);
    double term(bool);
    double prim(bool);
}

namespace Lexer {
    enum class Kind : char {
        name , number, end,
        plus='+', minus='-', mul='*', div='/', print=';', assign='=', lp='(', rp=')'
};

    struct Token {
        Kind kind;
        string string_value;
        double number_value;
    };

    class Token_stream {
    public:
        Token(istream& s) : ip{&s}, owns(false}, ct{Kind::end} { }
        Token(istream*p) : ip{p}, owns{true}, ct{Kind::end} { }

        ~Token() { close(); }

        Token get();      // wczytuje i zwraca nastpny token
        Token& current(); // ostatnio wczytany token

        void set_input(istream& s) { close(); ip = &s; owns=false; }
        void set_input(istream* p) { close(); ip = p; owns = true; }
    private:
        void close() { if (owns) delete ip; }

        istream* ip;          // wskanik do strumienia wejciowego
        bool owns;            // czy Token_stream jest wacicielem istream?
        Token ct {Kind::end}; // current_token
    };

    extern Token_stream ts;
}

namespace Table {
    extern map<string,double> table;
}

namespace Error {
    extern int no_of_errors;
    double error(const string& s);
}

namespace Driver {
    void calculate();
}
---------------
// lexer.cpp:

#include "dc.h"
#include <cctype>
#include <iostream> // niepotrzebne: jest ju w dc.h

Lexer::Token_stream ts;

Lexer::Token Lexer::Token_stream::get() { /*...*/ }
Lexer::Token& Lexer::Token_stream::current() { /*...*/ }
---------------
namespace Lexer { /*...*/ }
---------------
namespace Lexer { // z pliku dc.h
    //...
    class Token_stream {
    public:
        Token get();
        //...
    };
}

//...
Lexer::Token Lexer::Token_stream::get() { /*...*/ }
---------------
// parser.cpp:

#include "dc.h"

double Parser::prim(bool get) { /*...*/ }
double Parser::term(bool get) { /*...*/ }
double Parser::expr(bool get) { /*...*/ }
---------------
// table.cpp:

#include "dc.h"

std::map<std::string,double> Table::table;
---------------
// error.cpp:

#include "dg.h"
// wicej dyrektyw #include lub deklaracji

int Error::no_of_errors;
double Error::error(const string& s) { /*...*/ }
---------------
// main.cpp:

#include "dc.h"
#include <sstream>
#include <iostream> // niepotrzebne: jest ju w pliku dc.h

void Driver::calculate() { /*...*/ }

int main(int argc, char* argv[]) { /*...*/ }
---------------
// parser.h:
namespace Parser { // interfejs dla uytkownikw
    double expr(bool get);
}
---------------
// parser_impl.h:

#include "parser.h"
#include "error.h"
#include "lexer.h"

using Error::error;
using namespace Lexer;

namespace Parser { // interfejs dla implementatorw
    double prim(bool get);
    double term(bool get);
    double expr(bool get);
}
---------------
// parser.cpp:
#include "parser_impl.h"
#include "table.h"

using Table::table;

double Parser::prim(bool get) { /*...*/ }
double Parser::term(bool get) { /*...*/ }
double Parser::expr(bool get) { /*...*/ }
---------------
// error.h:

#include<string>

namespace Error {
    int Error::number_of_errors;
    double Error::error(const std::string&);
}
---------------
// error.cpp:

#include "error.h"

int Error::number_of_errors;
double Error::error(const std::string&) { /*...*/ }
---------------
// lexer.h:

#include<string>
#include<iostream>

namespace Lexer {

    enum class Kind : char { /*...*/ };

    class Token { /*...*/ };
    class Token_stream { /*...*/ };

    extern Token_stream is;
}
---------------
//lexer.cpp:

#include "lexer.h"
#include "error.h"
#include <iostream>     // niepotrzebne: jest ju w pliku lexer.h
#include <cctype>

Lexer::Token_stream is; // oznacza domylnie "wczytaj z cin"

Lexer::Token Lexer::Token_stream::get() { /*...*/ };
Lexer::Token& Lexer::Token_stream::current() { /*...*/ };
---------------
// table.h:

#include <map>
#include <string>

namespace Table {
    extern std::map<std::string,double> table;
}
---------------
// table.cpp:

#include "table.h"

std::map<std::string,double> Table::table;
---------------
// main.cpp:

#include "parser.h"
#include "lexer.h"  // aby mona byo ustawia ts
#include "error.h"
#include "table .h" // aby mona byo predefiniowa nazwy
#include <sstream>  // aby mona byo przekaza argumenty funkcji main() do strumienia acuchw

namespace Driver {
    void calculate() { /*...*/ }
}

int main(int argc, char* argv[]) { /*...*/ }
---------------
// error.h:

#ifndef CALC_ERROR_H
#define CALC_ERROR_H

namespace Error {
    //...
}

#endif // CALC_ERROR_H
---------------
int main() { /*...*/ }
int main(int argc, char* argv[]) { /*...*/ }
---------------
double x = 2; // zmienne nielokalne
double y;
double sqx = sqrt(x+y);
---------------
int& use_count()
{
    static int uc = 0;
    return uc;
}
---------------
void f()
{
    cout << ++use_count(); // odczyt i inkrementacja
    //...
}
---------------
int x = 3;
int y = sqrt(++x);
---------------
void exit(int);
---------------
void my_cleanup();

void somewhere()
{
    if (atexit(&my_cleanup)==0) {
        // funkcja my_cleanup zostanie wywoana przy normalnym zamykaniu programu
    }
    else {
        // ups, za duo funkcji atexit
    }
}