11.07.2015 Views

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

PicC 9.50 dsPIC Manual.pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C Language FeaturesStorage Class and Object Placementconst int * cip = &ci ;int * const icp = &i ;const int * const cicp = &ci ;The first example is a pointer called cip. It contains the address of an int object (in thiscase ci) that is qualified const, however the pointer itself is not qualified. The pointermay be used to read, but not write, the object to which it references. The contents of thepointer may be read and written by the program.The second example is a pointer called icp which contains the address of an int object(in this case i). Since this object is not qualified, it is a data space object which isreferenced by the pointer and this object can be both read and written using the pointer.However, the pointer is qualifed const and so can only be read by the program —it cannot be made to point to any other object other than the object whose addressinitializes the pointer (in this case i).The last example is of a pointer called cicp which is itself qualified const and whichalso holds the address of an object that is also qualified const. Thus the pointer canonly be used to read the object to which it references and the pointer itself cannot bemodified so it will always reference the same object during the program (in this caseci).3.5 Storage Class and Object PlacementObjects are positioned in different memory areas dependant on their storage class and declaration.This is discussed in the following sections.3.5.1 Local VariablesA local variable is one which only has scope within the block in which it was defined. That is, it mayonly be referenced within that block. C supports two classes of local variables in functions: autovariables which are normally allocated in the function’s stack frame, and static variables whichare always given a fixed memory location and have permanent duration.3.5.1.1 Auto VariablesAuto (short for automatic) variables are the default type of local variable. Unless explicitly declaredto be static a local variable will be made auto, however the auto keyword may be used if desired.auto variables are allocated either to spare registers, or onto the stack. The variables will not39

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!