??? 07/28/06 16:38 Read: times |
#121285 - Learning C Responding to: ???'s previous message |
The problem lied in a combination of:
- I am not a C guru, apparently he was not either - in C, except gurus, nobody knows what does "int" mean (even "short" or "long" won't make it any better) - gcc made an unexpected retyping (expansion) and sign extension when shifting I don't mean to sound uppety but there is a benefit to either/both: * Taking a C course from a proper educational institution, with and instructor that understands the philosophy of the language. * Reading the original bible of C, K & R. Data types, type casting, promotion are all fundamentals. Perhaps not the gee-wiz stuff, but ESSENTIALS. Learning C yourself or from a "21 Days" book can cost you dearly in the end. There are some books that are really good on the basics, but it's been so long that I've cracked one that I can't recall the titles. It's like anything, once you cement the fundamentals in your head you don't really have to think about them anymore. BUT you do need to have a critical eye on the compiler, because the atomic data types (int) will be different. That's why so many people use terminology like U8, S8 U16, U32 and the like. The first thing you do with a new compiler is learn the data sizes. These days most compilers will have some kind of "defines.h" file that will do this for you. On a final note, ALWAYS use an unsigned data type unless you have a reason not to. NEVER just go "int myvar". ALWAYS "unsigned int myvar" unless you know you will be dealing with negative values. GB |
Topic | Author | Date |
How long we see 8051 | 01/01/70 00:00 | |
unofficial history of 8051 | 01/01/70 00:00 | |
History, or prediction? | 01/01/70 00:00 | |
It seems to gain, not lose | 01/01/70 00:00 | |
Does it matter? | 01/01/70 00:00 | |
Double negative? | 01/01/70 00:00 | |
to C or not to C | 01/01/70 00:00 | |
Defintely 'C'! | 01/01/70 00:00 | |
yeah, let's flame! | 01/01/70 00:00 | |
Defintely 'C'! | 01/01/70 00:00 | |
arguments | 01/01/70 00:00 | |
An example for 8051/AVR | 01/01/70 00:00 | |
contra-example for 8051/AVR | 01/01/70 00:00 | |
A slight mistake | 01/01/70 00:00 | |
stdint.h | 01/01/70 00:00 | |
That's your trouble, then! | 01/01/70 00:00 | |
Compiler independant | 01/01/70 00:00 | |
C is not better | 01/01/70 00:00 | |
bringing 2 togethert | 01/01/70 00:00 | |
Opening pandora's box | 01/01/70 00:00 | |
Learning C | 01/01/70 00:00 | |
for a beginner ...![]() | 01/01/70 00:00 | |
are You sure? | 01/01/70 00:00 | |
Portability and scars | 01/01/70 00:00 | |
I'm an ASM Guru but | 01/01/70 00:00 | |
why discuss the rare exception tha same apply | 01/01/70 00:00 |