C Programming
xv6
xv6 Folder Structure
mkfs
user
kernel
Kernel
Kernel is the first program that runs when the computer is turned on
Everything that happens in that program happens in the kernel space
User
Every program that is not in the kernel space
C Fundamentals
Header Files
Standard headers
Operating System headers
int main()
This is the main function that OS will run when it runs your program.
argc
refers toarg[]
refers to
Types
int
32-bit signed integerunsigned int
32-bit unsigned integershort
16-bit signed shortunsigned short
16-bit unsigned shortlong
andunsigned long
aren't useful in xv6 contextIn general, you'd want to use
uint32_t
or similar types for normal programmingsigned char
8-bit signed charunsigned char
8-bit unsigned charchar
is neither unsigned nor signed. We don't use it for arithmetic. We will use it for generic blobs of bytes or raw data.
Pointers
Pointer is a variable whose value is the address of another variable
Arrays
Static arrays don't change size. They act like a pointer in some of use cases.
(void*) is put for printf to avoid a compiler warning
What is the difference between a pointer and an array? sizeof
array is equal to the size of the array in bytes. sizeof
pointer is equal to the size of an address, which is 8 bits or 1 byte.
Buffer
Buffer is an informal name for an unstructured collection of bytes
Why is sizeof and strlen different? strlen() iterates over the buffer and looks for the value zero. So it terminates when it sees zero. sizeof does not do that.
When you write the 0 byte, you sometimes call it the null byte.
Last updated