Monday, March 29, 2010

Pointer (Coding skills & technique)


Interlude:

Or pointes, these could be one of the challenging scheme a programmers must be adept or skillful to . Almost data declarations in a compiler epscially to an objected oriented programming languages ,a pointer is a bit extra technique which is interesting to be learned.Basically, one reason is the minimizations of coding and the eficacy of applying it in a given program.

Here , we coud have a look of some methods how we would be able to learn adopting and simpliying the use of a pointer to debug a source code.My experienced way back then in dealing with this "pointer" seriously was the challenged that convinced me in porting a TCP/IP Stack code from one c compiler to another(AVR glib libraries to CCS libraries and hopefully to SDCC).

Another are the encouragement that I need to convinced these kind of tricks by myself; 1)I am able to run PIC16F877a as an ethernet server and include details of applications to it, 2) published the documents if nescessary for free.So I decided to recode first the Microchip TCP/IP Stack -a sort of: enc28j60(h,c) , mac(h,c) then the stacktask(h,c) before I can make any algorithm or programming flow of my own style.

Here is that thing I was thingking then-a simple ping reply
main()
{
initialise :
MCU
ENC28j60
tweaking the TX/RX between the two interface
detect for a raw packet then send back to it.
}

Even with a copied uChip TCP/IP Stack it couldn't been easy as what had been thought than done -especillay when porting the code.So,need to consider really the functions of buffer,register and bank selector in enc28j60 as to how I could minimized the program to fit exactly from 32Kb to an 8K!(RAM) flash memory of PIC16F877a. In order to make it more definitive, it is the pointer issues that burned my eybrows -just on porting code of the program.And now, let us discussed a learning schemes how pointer/s are adopted using its advantages in coding a program instead.

Let's take a scrutinizations to these:
Pointers and Constants:
Given the following:
char buffer[100];
char name[20];

//pointer to const char
const char *p = buffer;
p = name; // ok
*p = ’x’; // error!

//const pointer to char
char * const p = buffer
*p = ’x’; // ok
p = name; // error!
const char space = ’ ’;
const char *p = &space; // ok
char *q = &space; // error!

No comments:

Post a Comment