cppannotations/annotations/yo/intro/cascpp.yo
Frank B. Brokken 777b182edd Moved all files but 'excluded', 'sf', and 'sourcetar' to ./annotations
This allowed me to standardize the sourcetar and sf/* scripts: the base
    directory (containing ./git) is now empty, except for maintenance scripts,
    while the source files and build scripts of the annotations are stored in
    a subdirectory of their own.
2013-05-29 20:44:08 +02:00

50 lines
2 KiB
Text

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.
)