Interactive Bootstraps“Numbers in detail” →Your first header

812cc7342a75e6ef271833cc3b9d5fbb2c37fc9a
🐶
Add hexdump header
Hexdump will be a useful debug tool, as well as the first piece of
interactive tool.

⟨hexdump.h⟩≡

@@ -0,0+1,4@@
1
+#include <stddef.h>

🐶

First we include some standard definitions, specifically the size_t which is a numeric type that can represent any size.

2
+
3
+/// Print the hexdump of the data of size len onto the stdout.

🐶

This is still just a comment, because anything after the two slashes // is a comment, including the third slash, but some tools treat it specially (for example doxygen, and some text editors/language servers show these types of comment when hovering over the function name, even where it is used) so it’s a good habit to document functions with a brief description like this.

4
+void hexdump(const void *data, size_t len);

🐶

And this is our first function prototype – the prototype in this case just means describing the function without implementing it: what its name is, what types are the arguments, and what type it returns.

🐱

Presumably const means constant, and I know reading right-to-left that data is a pointer to a constant void – what is void exactly?

🐶

Yes, const means constant, in this case it means a pointer to a void which is constant. Not to be confused with for example void * const, which is a constant pointer to a void. The former means the data the pointer is pointing to won’t be modified, the latter means the value of the pointer won’t be modified but the data might be.

In this case, we just want hexdump to look at the data, but not modify it.

A pointer to a void means a pointer to some type, that we don’t know any details about. It is useful as a “generic pointer”, and in C any pointer can automatically be converted to (known as an implicit type cast) a void pointer and vice versa.

And in the return value of hexdump, the void means the function doesn’t return any value (it just prints to the screen, but that is not part of the function type signature).