1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
Prospective bf(C++) programmers should realize that bf(C++) is not a perfect
superset of bf(C). There are some differences you might encounter when you
simply rename a file to a file having the extension tt(.cc) and run it through
a bf(C++) compiler:
itemization(
it() In bf(C), ti(sizeof)tt(('c')) equals tt(sizeof(int)), tt('c') being
any ASCII character. The underlying philosophy is probably that tt(char)s,
when passed as arguments to functions, are passed as integers
anyway. Furthermore, the bf(C) compiler handles a character constant like
tt('c') as an integer constant. Hence, in bf(C), the function calls
verb( putchar(10);)
and
verb( putchar('\n');)
are synonymous.
By contrast, in bf(C++), tt(sizeof('c')) is always 1 (but see also section
ref(WCHAR)). An tt(int) is still an tt(int), though. As we shall see later
(section ref(FunctionOverloading)), the two function calls
verb( somefunc(10);)
and
verb( somefunc('\n');)
may be handled by different functions: bf(C++) distinguishes functions not
only by their names, but also by their argument types, which are different in
these two calls. The former using an tt(int) argument, the latter a tt(char).
it() bf(C++) requires very strict i(prototyping) of external
functions. E.g., in bf(C) a prototype like
verb( void func();)
means that a function tt(func()) exists, returning no value. The
declaration doesn't specify which arguments (if any) are accepted by the
function.
However, in bf(C++) the above declaration means that the function tt(func())
does em(not) accept any arguments at all. Any arguments passed to it
result in a compile-time error.
Note that the keyword ti(extern) is not required when declaring functions. A
function definition becomes a function declaration simply by replacing a
function's body by a semicolon. The keyword tt(extern) em(is) required,
though, when declaring variables.
)
|