Preliminary: some
historical background of C
- The designer of
the C programming language
(Dennis Ritchie)
wants to:
- make
coding in C
fast (= less typing)...
|
- Example:
- Another area where
C
minimizes
typing is:
- Ritchie made
the
C compiler do
something "strange"
to avoid
writing
function declarations...
|
The implicit
function declaration made by the
C compiler
- Ritchie
noticed
that
the
most commonly used
data types of
parameters
in functions are:
- The C compiler that
Richie
designed has a
built-in
implicit
function declaration
mechanism:
- When a
function is
used (= called)
before it was
defined,
the C compiler will
assume that:
- The data type of
each parameter is
int
- The return data type of
the function is
int
|
|
- The
implicit
function declaration
mechanism was
expanded
later as:
- The data type of the
parameter for
an integer typed value
is
int
- The data type of the
parameter for
a floating point typed value
is
double
- The
return data type of
the function is
int
|
|
Example
implicit
function declaration
DEMO:
demo/C/set1/param3.c
What happens if
the
implicit
function declaration is
wrong ?
DEMO:
demo/C/set1/param3b.c
param3b.c:13:8: error:
conflicting types for `square'
Recommendation for
beginning C programmers
❮
❯