Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
(Reek, Ch. 3)
0xfe4a10c5
(char *)
p
... 0xae12 0x0070 0x015e ...
(char)
0xfe4a10c4 0xfe4a10c5 0xfe4a10c6
0xfe4a10c6
0xfe4a10c5
(char
(char *)
*)
0xcda200bd
(char **)
p q
... 0xae12 0x0070 0x0071 ...
(char) (char)
0xfe4a10c4 0xfe4a10c5 0xfe4a10c6
???
int a; (int)
float f; a
???
(float)
f (char *)
17
int a = 17; (int) d o g NUL
(char) (char) (char) (char)
float 3.14; a
3.14
(float)
**pm = &m; m
The string literal ″dog″ generates a sequence
17
(int)
pa
The pointer pa will always point to the same address, but the
data content at that address can be changed:
*pa = 42;
pa
The pointer pa can be changed, but the data content that it’s
pointing to cannot be changed:
pa = &b;
pa
Neither the pointer pa nor the data that it’s pointing to can be
changed
file1.c file2.c
int f ( void ) { int g ( void ) {
Two
int a; distinct int a;
variables
} }
} }
Declaring a here is not strictly
necessary, since f() is within the
scope of the first a declaration
26 CS 3090: Safety Critical Programming in C
Dangers of external linkage
It’s a way to avoid the trouble (both for the programmer
and the machine) of passing parameters).
But... it can lead to trouble, especially in large multi-file
programs constructed by many people
Where exactly is the variable a declared?
What is all that other code (possibly in different files) doing
with a?
If I modify a in a certain way, is it going to mess up code
elsewhere that uses a?
It’s harder to reuse g() if it depends on a variable declared
elsewhere
} }
int f( void ) {