views:

161

answers:

4

I'm now really diving into my OS project, called ForestOS, but now I'm needing to dive more into some simple and basic things of C. As now I'm having many problems with the correct variable to use and functions.

I want resources that only talk about variables, functions and how to develop without headers(stdio.h, math.h and all the others).

+11  A: 

Best starting place is probably the book The C Programming Language.

The book was central to the development and popularization of the C programming language and is still widely read and used today.

Richard Ev
Cmon.. he still has to code his first "hello world"... shouldn't he at least follow a few free Internet tutorials before investing money in books? :)
littlegreen
@ littlegreen: He is attempting to write an OS; let's assume that he is past "hello world"!
Clifford
@Clifford I think your assumption may be a little off. Nathan has rather, let us say, "grandiose" ideas about his own programming abilities.
anon
Of course! And I've already spent my money. I've bought this book since 1 minute and I'm going to spend more, this is the best project that I've already started! **:D**
Nathan Campos
Lol let's hope at least :)
AntonioCS
Alright then, all cheer for Nathancamp-OS!
littlegreen
If you're going to spend all that time working in C, buying one book is a reasonable investment, and that particular book will be very useful.
David Thornley
I hope it will be! **:)**
Nathan Campos
Clifford
anon
dmckee
littlegreen
Richard Ev
+3  A: 

A guide to OS development suggests CProgramming.com as the best place to start. There's tutorials, links to further resources, and everything for free.

littlegreen
+1 'Guide to OS dev' seems like a good site (not that I plan to build my own os)
AntonioCS
+1 But I prefer http://osdev.org that have a very nice wiki.
Nathan Campos
+3  A: 

Building an OS is non-trivial, I suggest if you are "having many problems with the correct variable to use and functions" then you may be attempting to walk before you can run!

Quote:

how to develop without headers(stdio.h, math.h and all the others).

I assume that you actually mean that you want to code without using the standard library rather than "without headers". Header files are intrinsic to modularisation in C; if you did not use headers, your code would have to be one monolithic module. Don't confuse headers with libraries.

However, even then there is no need not to use the standard library when writing 'bare-metal' code. You simply need a library that does not have OS dependencies, and you write the low level glue code to make things like stdio and memory allocation work on your system. Such a library is Newlib for example. It will make your life a whole lot easier if you have standard library support.

Clifford
+1, Newlib seems like a timesaver. Unless of course, you want to reinvent the *whole* wheel. Wheel 2.0.
littlegreen
@littlegreen: lol, Yeah I want to reinvent the wheel and make a Wheel 2.0, but I'm going to use Newlib as a base for learning. **;-)**
Nathan Campos
Is low-level C = C without headers? - Like low-level Assembly and HLA?
Nathan Campos
Essentially, C is a high-level language. Low-level would be writing assembler/processor code directly, which C cannot do. But there is a diff. between high- and low-level C, which is basically what Clifford describes: whether you link your program to libraries or not. Headers are irrelevant (although you usually include headers in order to describe functions in libraries, to which you subsequently link your program....)
littlegreen
@Nathan: The term "low level" was used to refer to the purpose of the code, not the language used or its complexity or even if it uses other headers - the answer to that is no, and that should have been clear from the first part of my answer. "Low level" in this context means the level of least abstraction, that interfaces directly with the hardware or perhaps BIOS services for example. It by no means implies that the code is either simple or primative. I have no idea what HLA means.
Clifford
+1  A: 

You only need headers to provide declarations of functions and external variables.

It is possible to eliminate the header files and provide your declarations within the translation unit (a.k.a. source file). Although possible, this is not recommended.

Here is an example of a legal C program without header files:

/* Forward declaration of main(). */
int main(void);

/* Definition for main() function. */
int
main(void)
{
  return 13; /* 42 is such an overrated number. */
}

Some reasons for using header files are: code / typing reduction and single point of maintenance. If two modules need the same structure declaration, placing it in a header file will reduce typing (you only have to #include it in both files instead of copying it into both files). Also, if you need to change any declaration, if it is copied, you'll have to hunt down all copies and change every instance vs. making one change in a header file.

As far as standard header files, such as math.h and stdio.h, if you don't need them, don't include them. An OS should not require stdio.h, but may use math.h. Most standard header files do not contribute to the code size; only to the compile time.

I highly suggest you focus on the correctness of your OS and don't worry about trivialities such as header files. After your OS is working correctly and robust, go ahead and trim the fat.

Thomas Matthews