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.

Supported Data Types and VariablesC Language FeaturesIn this case, the structure will be placed into the program space and each member will, obviously, beread-only. Remember that all members must be initialized if a structure is const as they cannot beinitialized at runtime.If the members of the structure were individually qualified const but the structure was not, thenthe structure would be positioned into RAM, but each member would be read-only. Compare thefollowing structure with the above.struct {const int number;int * const ptr;} record = { 0x55, &i};3.4.8 Standard Type QualifiersType qualifiers provide information regarding how an object may be used, in addition to its typewhich defines it storage size and format. HI-TECH C supports both ANSI qualifiers and additionalspecial qualifiers which are useful for embedded applications and which take advantage of the <strong>dsPIC</strong>architecture.3.4.8.1 Const and Volatile Type QualifiersHI-TECH C supports the use of the ANSI type qualifiers const and volatile.The const type qualifier is used to tell the compiler that an object is read only and will not bemodified. If any attempt is made to modify an object declared const, the compiler will issue awarning. User-defined objects declared const are placed in a special psects in the program space.Obviously, a const object must be initialised when it is declared as it cannot be assigned a value atany point at runtime. For example:const int version = 3;The volatile type qualifier is used to tell the compiler that an object cannot be guaranteed to retainits value between successive accesses. This prevents the optimizer from eliminating apparentlyredundant references to objects declared volatile because it may alter the behaviour of the programto do so. All Input/Output ports and any variables which may be modified by interrupt routinesshould be declared volatile, for example:volatile static unsigned int TACTL @ 0x160;Volatile objects may be accessed using different generated code to non-volatile objects.36

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

Saved successfully!

Ooh no, something went wrong!