So, in my efforts to find sources to learn C from, I've found this:
http://tifreakware.net/documents/learnc.pdf
My goal is to try to use this to learn C so I can get cracking on CE projects. What I'd like to do is copy example code used in the book, put in a post and also post the code to work on the CE (in whatever examples would work to do this, I'm sure not everything will).
Thoughts on this resource? Thoughts on the examples idea?
I would recommend against that particular tutorial, as, for example, 8.3.1 "About not using Element 0" is pretty terrible advice, especially on a limited memory platform like the CE.
Here's the basic rundown on what a TI-BASIC programmer should know about C:
- You can have variables that whose value is the address in memory of another variable. This is called a "pointer". You can access the variable being "pointed to" using the * operator ("pointer de-reference") and you can create a pointer to a variable by taking its address using the & operator ("address-of"). Bad things can happen when you have pointers which you expect to be pointing somewhere, and aren't (which can happen in a couple ways, either by forgetting to initialize them, or by keeping them too long after the thing they point to doesn't exist anymore, or by setting them manually to a "bad" value, like NULL).
The closest analogue to this in BASIC is when you are using a variable as an index into either a List or a Matrix, you can think of that variable as being a pointer, and in fact, in C, there is a very close relationship between array indexing, and pointers: you can access the 5th element of an array either like a[5], or like *(a+5).
- There are several different ways that variables can be stored, and choosing the right one is important.
- "Global variables" can be declared outside of any function. By default you can even access from other files, using the extern key word to declare them in multiple places, and have them all be stored in the same place in memory. If you want to restrict a global variable to the current file, you instead declare it as static.
- "Stack variables" are local variables within a function. The storage for them is automatically set aside when you call the function, and removed when the function returns. This means you have to be very careful about taking pointers from them, because if the pointer "escapes" the function and somebody tries to use it, all sorts of craziness can happy since the memory it is pointing to is unlikely to still be holding the correct thing. You can also declare stack variables as static, which means that a single copy will be remembered across every time a function is called. This allows you to, for example, count the number of times the function has been called from inside the function itself.
- "heap variables" are variables for which you specifically request memory, using a call to "malloc", and which you must specifically dispose of, with a call to "free". Losing a pointer to a variable before it is freed will cause your program to leak memory (just like GOTOing out of a loop in BASIC), and accidentally freeing something more than once can crash the program.
- Unlike TI-BASIC, there is no special difference between For and While.
Code:
for(setup; test; update){ some stuff here; }
is equivalent to
Code:
setup;
while(test){
some stuff here;
update;
}
However there is an additional type of loop, with similar behavior to Repeat:
Code:
do{ some stuff here; } while(test);
will always do some stuff here before the first test.
Yes, but I have -no- knowledge of C commands. Nothing. The only way I am going to learn about them is from a tutorial of some form. And as I get to each section, I can ask questions about what is there, and awesome people here, as they have time, can help correct it.
I prefer more of an offline source than an online one, in the event of net loss (which seems to happen far too frequently here <.< ) Do they have something I can download similar to that of asm in 28 days?
I think it's better to learn C for a desktop to get a grip on the language before jumping into C for embedded platforms. The reason is that the deviations from the standard library and the optimizations that such a tiny processor as the Z80 demands probably won't help in forming a strong foundation of the language.
I would recommend going to the library. There is an amazing amount of resources there. I learned by reading Programming in C by Stephen G. Kochan, which I would recommend. The problem is that you dont have a compiler with it.
elfprince13 wrote:
I would recommend against that particular tutorial, as, for example, 8.3.1 "About not using Element 0" is pretty terrible advice, especially on a limited memory platform like the CE.
definitely agree. this book is full of terrible practices and bad habits and generally reads like it was written by somebody self taught who's only ever used C for small, one-person hobbyist programs that crash half the time
oldmud0 wrote:
I think it's better to learn C for a desktop to get a grip on the language before jumping into C for embedded platforms. The reason is that the deviations from the standard library and the optimizations that such a tiny processor as the Z80 demands probably won't help in forming a strong foundation of the language.
agree with this as well
if you can handle the ideology, Learn C The Hard Way is a wonderful place to get to know C and how it's actually used on modern systems in the RealWorld™
would also recommend taking a look at the styling used by the linux kernel team, as it's pretty ubiquitous
from there, once you've built up some competence, it's far easier to adapt your style to work with a low-resource environment like the CE
as an aside, there are a few popular disagreements when it comes to styling certain things. for example, when declaring a new structure, many people will do something like this, for the sake of brevity:
Code:
typedef struct thing_s thing_t;
struct thing_s {
int a;
int b;
};
the linux kernel guide suggests, very vehemently, that this should instead be left as
Code:
struct thing {
int a;
int b;
};
without defining a new type. still others, like the author of the book above, will use upper-case for types:
Code:
typdef struct Thing {
int a;
int b;
} Thing;
as long as you're familiar enough with these different style choices to recognise them (and, more importantly, the things they all keep consistent such as snake_case vars / funcs, UPPER_CASE macros, and tabs, not spaces), you should have no trouble collaborating with "C people"
good luck!
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
»
Go to Registration page
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum