11.2 Notes on Compiling a C Program with the C++ Compiler

(1)

Functions with Prototype Declarations

Before using a function, a prototype declaration is necessary. At this time, the types of the parameters should also be declared.

extern void func1();
void g()
{
    func1(1); // Error
}
extern void func1(int);
void g()
{
    func1(1); // OK
}

(2)

Linkage of const Objects

Whereas in C programs const type objects are linked externally, in C++ programs they are linked internally. In addition, const type objects require initial values.

const cvalue1;     // Error
 
const cvalue2 = 1; // Links internally
const cvalue1 = 0;        // Gives initial value
 
extern const cvalue2 = 1; // Links externally as a C program

(3)

Assignment of void*

In C++ programs, if explicit casting is not used, assignment of pointers to other objects (excluding pointers to functions and to members) is not possible.

void func(void *ptrv, int *ptri)
{
    ptri = ptrv; // Error
}
void func(void *ptrv, int *ptri)
{
    ptri = (int *)ptrv; // OK
}