Nokia official training (Symbian 4300) Notes (IV)-basic data types and naming rules

Source: Internet
Author: User
Tags coding standards

Basic TypesIn Symbian, many basic types of C ++ have been redefined. It is best to use Symbian for the following reasons:
  • All Symbian APIs are redefined using symbianc.
  • In the future, when Symbian OS is changed from 32-bit to 64-bit, the support will be better.
  • This is what Symbian C ++ coding standards requires.
IntegersTypedef signed int tint; signed int in C ++, 32-bit. The basic usage is similar. Typedef unsigned int tuint; generally used for counters or flags ). Other int types: tint64, tint32, tint16, and tint8; there is also a tuint version. TextThe text type is basically not used in Symbian programming, but generally uses a descriptor ). Ttext is 16 bits by default. BooleanTypedef int tbool; two enumerated values are available: etrue and efalse. Tbool variables should not be directly compared with eture and efalse. As follows: tbool flag = etrue;
If (FLAG) // If (! Flag)
{
Flag = efalse;
} Floating PointThe support for floating point numbers depends on the processor. If there is no FPU, the efficiency is very low, so it is best not to use floating point numbers. If necessary, convert it to an integer as much as possible. Typedef float treal32; typedef double treal64; typedef double treal; TanyTypedef void Tany; Tany is generally used as a pointer only. In other cases, it is better to use void. Tany * myfunction (); void mytherfn (); Tany * is used in many Symbian APIs, such as static tuint8 * Copy (Tany * atrg, const Tany * asrc, tint alength ); EnumerationsEnum tstate {eoff, Eon, einit}; The Enumeration type should start with t, and the enumerated value should start with E. Tstate state = getstate ();
If (State = Eon)
{
// Do something here
} Coding conventionsClass T: only contains values, not pointers and external resources, and allocates space on the stack. Tversion osversion = User: Version (); Class C: All classes whose memory needs to be allocated must inherit from cbase and start with C. Class cexample: Public cbase
{
PRIVATE:
Cdescarrayflat * iarray;
} Cexample * example = new (eleave) cexample; r class: contains the handler pointing to a resource. Rtimer timer;
Timer. createlocal (); m class: defines an interface that generally only contains pure virtual functions, does not contain member data, reduces dependencies between classes, and is used to receive callback messages. Class meikstatuspaneobserver
{
Public:
Virtual void handlestatuspanesizechange () = 0;
} Any class that implements the meikstatuspaneobserver interface must implement the handlestatuspanesizechange () function. Variable naming conventions
  • The member variable starts with "I ".
  • The parameter starts with "".
  • Dynamic variables can start with lowercase letters.
  • Constant starts with "K"
  • Do not use global variables. Do not use Global static variables.
Functions
  • The function starts with an uppercase letter, for example, addfilenamel ();
  • Deletion of an object ended with d
  • End with L to indicate function leave
  • Ending with C indicates that an item is put on the cleanup stack.
CastingCasting is used for conversion between classes and types. The C syntax can still be used in Symbian. Dynamic_cast: not supported. There is no rtti in Symbian. Static_cast: converts a base class into an inherited class. Tint intvalue = 0xff;
Tuint8 bytevalue = static_cast <tuint8> (intvalue); reinterpret_cast: converts a pointer type to another pointer type, such as integer to point type or vice versa. Tuint32 fourbytes = 0;
Tuint8 * byteptr = reinterpret_cast <tuint8 *> (& fourbytes );
Byteptr ++;
* Byteptr = 0xff; const_cast: removes the const attribute of a class. Post readingThe basics of Symbian programming are things we encounter every day. The last part of the casting is a little hard to understand, so it is better for others to get used to it. In common, since we chose Symbian, we should use the Symbian convention to write programs.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.