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.
argcrefers toarg[]refers to
Types
int32-bit signed integerunsigned int32-bit unsigned integershort16-bit signed shortunsigned short16-bit unsigned shortlongandunsigned longaren't useful in xv6 contextIn general, you'd want to use
uint32_tor similar types for normal programmingsigned char8-bit signed charunsigned char8-bit unsigned charcharis 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