??? 01/01/11 04:50 Read: times |
#180376 - Pointers are normally the main problem when learning C Responding to: ???'s previous message |
The "normal" big problem with C is the concept of pointers. That you sometimes works directly with variables. And sometimes have variables that are just addresses to variables and where you do indirect accesses to variables.
The next thing people usually have problems with is that pointer variables allows arithmetic on either the pointer or on the value the pointer points to. So i = i+1 and p = p+1 does completely different things, if i is a normal integer variable, while p is a pointer variable. But the big troubles with pointers is that it is something that is important to learn while working with embedded projects. For a number of reasons, some "magic" variables just must be located at specific addresses or the program will not work. In some situations, the compiler will add other methods to hide this allocation of the magic variables. But the developer just needs to understand the concept anyway. On a 8051, the I/O ports are basically a special form of variables. But a type of variables that the compiler itself (with help of an include file) manages to map to the physical port in the processor. The datasheet for the processor - or for the assembler instruction set - will be totally based on the concept of addresses and addressing modes. How to access different types of variables. Another issue people tends to have problems with is function parameters - the difference between sending a "normal" variable as a parameter, and sending a pointer as parameter. When sending a pointer (called call by reference), then the value that the pointer points to can be modified by a function. When sending a "normal" parameter, the value of the parameter are basically duplicated (call by value) so a function gets a copy of the value to play with. The above three situations covers a huge percentage of the conceptual problems a beginner normally has when looking at C. A large part of the C language is based on pointers, so people don't have much wiggle room before they have to learn about pointers and their physical meaning. |