Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
For you to get the most out of this book, let's quickly run through the notation we use. The text is straightforward, and where we quote example code, resource files, or project definition files, they will be highlighted as follows:
This is example code;
C++ code for Symbian OS uses an established naming convention. We encourage you to follow it in order for your own code to be understood most easily by other Symbian OS developers, and because the conventions have been chosen carefully to reflect object cleanup and ownership, and make code more comprehensible. An additional benefit to using the conventions is that your code can then be tested with automatic code analysis tools, which can flag potential bugs or areas to review.
If they are unfamiliar, the best way to get used to the conventions is to look at code examples in this book, and those provided with your chosen SDK.
The first letter of class names is capitalized:
class TColor;
The words making up variable, class, or function names are adjoining, with the first letter of each word capitalized. Classes and functions have their initial letter capitalized while, in contrast, function parameters, local, global, and member variables have a lowercase first letter.
Apart from the first letter of each word, the rest of each word is given in lower case, including acronyms. For example:
void CalculateScore(TInt aCorrectAnswers, TInt aQuestionsAnswered); class CActiveScheduler; TInt localVariable; CShape* iShape; class CBbc;//Acronyms are not usually written in upper case
Member variables are prefixed with a lowercase 'i', which stands for 'instance'.
TInt iCount; CBackground* iBitmap;
Parameters are prefixed with a lowercase 'a', which stands for 'argument'. We do not use 'an' for arguments that start with a vowel.
void ExampleFunction(TBool aExampleBool, const TDesC& aName);
(Note: TBool aExampleBool rather than TBool anExampleBool).
Local variables have no prefix:
TInt localVariable; CMyClass* ptr = NULL;
Class names should be prefixed with the letter appropriate to their Symbian OS type (usually 'C', 'R', 'T', or 'M'):
class CActive; class TParse; class RFs; class MCallback;
Constants are prefixed with 'K':
const TInt KMaxFilenameLength = 256; #define KMaxFilenameLength 256
Enumerations are simple types, and so are prefixed with 'T'. Enumeration members are prefixed with 'E':
enum TWeekdays {EMonday, ETuesday, ...};A trailing 'L' on a function name indicates that the function may leave:
void AllocL();
A trailing 'C' on a function name indicates that the function returns a pointer that has been pushed onto the cleanup stack:
CCylon* NewLC();
A trailing 'D' on a function name means that it will result in the deletion of the object referred to by the function:
TInt ExecuteLD(TInt aResourceId);
Underscores are avoided in names except in macros (__ASSERT_DEBUG) or resource files (MENU_ITEM).
You'll notice that the curly bracket layout in Symbian OS code, used throughout this book, is to indent the bracket as well as the following statement:
void CNotifyChange::StartFilesystemMonitor()
{// Only allow one request to be submitted at a time
// Caller must call Cancel() before submitting another
if (IsActive())
{
_}LIT(KAOExamplePanic, "CNotifyChange");
User::Panic(KAOExamplePanic, KErrInUse);
}
iFs.NotifyChange(ENotifyAll, iStatus, *iPath);
SetActive(); // Mark this object active
}