prompter: What is function prototype in C programming

assistant: In C programming, a function prototype is a declaration of a function that specifies the function's name, return type, and the number and types of its parameters. It provides a way for the compiler to verify that calls to the function are made correctly, and to check that the function is defined correctly.

A function prototype typically appears at the beginning of a program, before the main function or any other functions that call the function being prototyped. It has the following general form:

return_type function_name (parameter_list);

Where:

- return_type: specifies the data type of the value returned by the function.
- function_name: specifies the name of the function.
- parameter_list: specifies the type and name of each parameter passed to the function, separated by commas.

Here is an example of a function prototype for a simple function that calculates the square of a number:
```
int square(int);
``` 
This prototype declares a function named square that takes an integer parameter and returns an integer value. Once the prototype is declared, the function can be defined later in the program, after all other function prototypes and before the function is called.

prompter: Ok great, can you tell me about functions that don't return a data type

assistant: In C programming, a function that does not return a data type is called a "void function." A void function is a function that performs a task but does not return a value. When declaring a void function, the function prototype takes the form:

void function_name(parameter_list);

Where:

function_name: specifies the name of the function.
parameter_list: specifies the type and name of each parameter passed to the function, separated by commas.

Here is an example of a void function prototype for a function that prints a message to the console:

void print_message(char*);

This prototype declares a function named print_message that takes a character pointer as a parameter and does not return a value.

Void functions are often used for tasks such as printing to the console, updating global variables, or modifying data structures. In these cases, the function's purpose is to modify state rather than to return a value.

prompter: Can a function have multiple prototypes?

assistant: When a function does not return a prototype, the word "void" is used to signify that nothing is returned.

Here is an example of a function prototype for a function that increments the pointed value:

```c
void increment(int*);
```

assistant: A function prototype is essentially a *stripped* declaration of a function that goes before the actual declaration of the function. For example, look at this piece of code:
```c
#include <stdio.h>

int main() {
  printf("%d\n", sum(1));
  return 0;
}

int sum(int x, int y) {
  return x + y;
}
```
If you look closely, you'll notice that, in the `main` function, `sum` is only called with one argument. Many compilers would happy compile this code, perhaps with a warning. For example, gcc will give you the warning `implicit declaration of function 'sum' [-Wimplicit-function-declaration]`, but proceed to yield a working executable.
When such call happens, the argument of interest(`y`, in this case), is undefined, and is likely a value on the stack(on 32-bit systems) or in one of the registers(on 64-bit system).
To avoid this behavior, you can add a **function prototype** at the top(the location actually doesn't matter, as long as its above potential callers, such as `main`!) of the file, like so:
```c
#include <stdio.h>

int sum(int, int); // This is the function prototype!

int main() {
  printf("%d\n", sum(1));
  return 0;
}

int sum(int x, int y) {
  return x + y;
}
```
As you can see, the function prototype is indeed just a stripped declaration: `int sum(int x, int y)` was turned into `int sum(int, int)`. Now, if we try compiling this code using gcc, we'll get the error `too few arguments to function 'sum'`, and no executable will be generated.

Function prototypes are a really important feature of C and should always be used to save hours of potential debugging.

prompter: Is there a flag I can set when calling gcc, in order for it to throw an error if any implicit function declarations are detected?

assistant: Yes, you can use the -Werror flag when calling gcc to treat all warnings as errors. This will cause gcc to stop compilation if it encounters any implicit function declarations, and will output an error message instead of a warning.

For example, you can use the following command to compile your code with the -Werror flag:

gcc -Werror -o my_program my_program.c

This will produce an error if any implicit function declarations are found in the code. However, keep in mind that this may also cause other warnings to be treated as errors, so you may want to use this flag carefully and only when necessary.