Brief guide to Symbian C++

… actually you can find this information on a dozen of other sources, but if you bothered (if this is so I will thank you) to click on my blog, it worth reading it.

Maybe the difference in between what is written here and on some other web resource, is that those things out here are  coming from a Symbian newbie, so …

Symbian developers from all over the world (I am addressing here to the beginners among you)  unissez vous !

Do you already have a C++ background and do you want to start learning about the worlds’ most deployed mobile operating system ? If you happily answer YES to both questions, you may need informations out here.

Many Symbian C++ books assume that you are already familiar with C++ but not that you have an in-depth knowledge of the operating system, actually many of them include some statements like this one:

If you are a developer targeting, or thinking of targeting, Symbian OS, this book will show you how to write the most effective C++. You will benefit from a greater understanding of the characteristic features and design of the operating system, and confidence in how to use them.

the author warns:

We encourage you to follow them too, 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.

… just taken from Symbian OS explained by Jo Stichbury, a Symbian OS and Symbian C++ golden reference

The general picture being drawn I will procede with Symbian C++ code conventions.

  1. Capitalization – each class name must be capitalized, rest of the letters must be in lower-case.
  2. CClass Instance1; //this is OK
    CCLASS Instance2; //this is NOT OK

  3. Instance member variableshave always in front of their name an ‘i’
  4. CClass iInstance; // just to "correct" the example above

  5. Arguments are prefixed with letter ‘A’
  6. CClass::Function (TInt aArgument1, TInt aArgument2)

  7. Constants are prefixed by letter ‘K’
  8. const TText KNumbers[] = { "zero", "one", "two", "three" }; //KNumbers is a Konstant


  9. A trailing ‘L’ on a function name indicates that the function may leave:
  10. void AllocL();

  11. A trailing ‘C’ on a function name indicates that the function returns a pointer that has been pushed onto the cleanup stack:
  12. Ccylon NewLC();

  13. A trailing ‘D’ on a function name means that it will result in the deletion of the object referred to by the function:
  14. TInt ExecuteLD(TInt aResourceId);

Class naming conventions: there are also some special types of classes, four in total: T classes, C classes, R classes, M classes. Those are named with the prefixes already mentioned

  1. T classes behave like fundamental built-in types, actually this is where the T comes from – typedef. It is said that they contain their data internally, meaning that they contain only funtamental types and cannot have pointers or references to other data. Usually T classes are instantiated on the stack, but depending on the size, if this take much space, they can be instantiated on the heap. T classes do not have an explicit destructor so in case if they are instantiated on the heap one must pay attention to the way corresponding objects are deleted.
  2. C classes, unlike T classes which keep a strong compatibility with C syntax, are more Symbian specific. All of them are inherited from CBase class, defined in e32base.h. Basically they have three characteristics, I will briefly mention them but they will make the subject for a deeper Symbian lecture:
    • CBase has a virtual destructor
    • zero initialization, every CBase object is “by default” 0 filled
    • private copy constructor and asignement operator
  3. class CExample : public CBase


      CExample(); // Guaranteed not to leave
      ∼CExample(); // Must cope with partially constructed objects
      void ConstructL(); // Second phase construction code - may leave


  4. R classes, with the R coming from resource, own an external resource handle. They are used often for creating client-server applications or for holding a file server session. Usually they contain only the corrsponding handle to the external resource and their instances are small. Initialization and resources release are not performed in the constructor or destructor but some special functions like Open(), Create(), Connect(), Close() handle those things.
  5. M classes – it comes somehow from “mixed”. It is the equivalent of Abstract classes in C++ and interfaces in Java, it has no member data, only pure virtual functions
  6. class MAnimal

      virtual void EatL() =0;

    class MDomesticAnimal : public MAnimal

      virtual void NameL() =0;

    class CCat : public CBase, public MDomesticAnimal

      virtual void EatL(); // From MAnimal, via MDomesticAnimal
      virtual void NameL(); // Inherited from MDomesticAnimal
      ... // Other functions omitted for clarity


  7. Static classes – they have no prefix letter, they cannot be instantiated, they provide useful code through static member functions, they can be called using scope resolution operator
  8. User::After(1000); // Suspends the current thread for 1000 microseconds

One more important thing to mention about coding conventions: there are Symbian built-in data types.
Those types are defined in e32def.h and are the following:

TInt instead of signed int, or “normal” int
TUint instead of unsigned int
TInt32, TInt16, TInt8 instead of long int, short int,signed char
TUint32, TUint16, TUint8instead of unsigned long int,unsigned short int,unsigned char
TInt64 instead of long long
TUint64 instead of unsigned long long
TText instead of unsigned short int
TText8, TText16 instead of unsigned short int,unsigned char
TReal32instead of the notorious double
TBool instead of int (this is, as you guessed, taken from A Symbian OS book and I’m wondering why is not mention bool as a C++ built-in correspondent)

TAny instead of the notorious void …. in any case, don’t have to bother yourself with memorizing all those, it is important to keep in mind only the “main” types: like TAny for void, TInt for int and … what is interesting TInt8 for signed char, it is curios to see signed/unsigned char

So, you will have to use the Symbian C++ built-in types from the left column instead of those in the left hand side which you are already familiar

That’s all folks folks for the moment ! I will be back with newer (for beginners, of course) stuff about Symbian I hope that after few similar posts I will be prepared to go through any Symbian code and not stare at it.


2 Responses to Brief guide to Symbian C++

  1. Pingback: What are <> in Symbian programming? « Bazaar 2.0

  2. kellogs says:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: