First, you've declared a function called insert_node
, but that doesn't matter. It's ok to declare functions, but not define them (i.e. not provide their code), as long as you don't use the function. This happens often in real life: headers define a lot of functions, and then at link time only the functions that are actually used need to be provided.
The warning concerns create_node
. Since there is no declaration of the function when you compile the main C file, the compiler makes some assumptions about its parameter types. It promotes all arguments: integer types smaller than int
(e.g. char
and short
) are promoted to int
; float
s are promoted to double
; pointer types are not converted. With your code, this happens to work because
- you're always passing arguments of the right type;
- none of the argument types are promoted.
If you changed the type of the data
parameter to long
, then the compiler would generate code to call the function assuming an int
type but the function would expect a long
argument. On a platform where int
and long
have different sizes, you might get garbage data, a crash, or other misbehavior.
If you changed the type of the data
parameter to char
, then the compiler would generate code to call the function assuming an int
type but the function would expect a char
argument. Again, you might find that the code uses wrong data, crashes, etc.
C generally gives you enough rope to hang yourself. If you cut a piece of rope in the wrong way, it might just happen to work. Or it might not.