C: Difference between revisions

Jump to navigation Jump to search
1,220 bytes added ,  15 years ago
m
no edit summary
[unchecked revision][unchecked revision]
mNo edit summary
mNo edit summary
Line 31:
 
To fix possible issues due to optimizations performed by processors on runtime (e.g. reordering instructions and memory accesses, caching memory) make sure you use [[atomic operation]]s or [[memory barriers]] where neccessary. This however isn't an optimization specific to the C/C++ language but rather platform and hardware specific.
 
== Learning C ==
If you don't know C and plan to use it for osdeving, it might be profitable to begin with some C language exercises.
A good start (you still need to find tutorials, these are just exercises):
* program that writes a string, asks for your name, writes two line breaks and writes another string and the provided name;
* implement strcopy(), strncopy(), strncmp() and other string manipulation functions. What is a buffer overflow?
* implement memmove() or memcpy(). Can you do it with inline assembly so it be faster?
* use inline assembly to perform CPUID and interpret the results;
* use typedefs to name uint32 for a 32-bit unsigned integer type; what type is signed 16-bit?
* use structs and pointers to implement a singly linked lists.
* divide the program with singly linked lists to main.c, list.c and list.h. What is a header guard?
* learn about inline, static, volatile; ternary operator; casts;
* use C preprocessor to write MAX, MIN macros; to print out the current function name, line number;
* use C preprocessor to write a log function which takes a level for the first argument, and uses printf() on the rest of the arguments if the level is higher or equal to current logging threshold.
 
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu