03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

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.

3.2.6 Summary<br />

Naming conventions are to some extent arbitrary: the only good thing you can say about<br />

most conventions is that life is better if everybody does the same thing.<br />

But you'll probably have noticed that Symbian OS naming conventions do address one<br />

particular issue: cleanup. That's a key topic, which will be covered in detail in <strong>Chapter</strong> 6. The<br />

distinction between C and T is fundamental to cleanup. R classes combine aspects of both C<br />

and T. The i prefix for members makes a fundamental distinction that is also cleanuprelated.<br />

And the suffix L on leaving functions indicates functions that may require cleanup.<br />

In other areas, Symbian OS naming conventions are neither worse nor better than anyone<br />

else's. All Symbian OS system and example code uses these conventions (with perhaps a<br />

couple of exceptions in the very oldest code), so your work will be made easier if you use<br />

them too.<br />

3.3 Functions<br />

Function prototypes in C++ header files can convey a lot of information including<br />

� whether it is imported from a DLL (indicated by IMPORT_C), inline and expanded<br />

from a header, or neither of these – that is, the function is private to a DLL;<br />

� whether it is public, protected, or private in the C++ sense (you have to scan up<br />

the file to see this, but it's effectively part of the prototype even so);<br />

� whether it is virtual (you have to scan down the base classes to be sure about this, but<br />

it's part of the signature) – and, if virtual, whether it's pure virtual;<br />

� whether it is static;<br />

� the return type (or void);<br />

� the name – usually a good hint at what the function does;<br />

� whether it can leave (L at the end of the name);<br />

� the type and method of passing for all the arguments (with an optional name that hints<br />

at purpose, though the name is not formally part of the signature);<br />

� whether there are any optional arguments;<br />

� whether it is const.<br />

If a function and its arguments (and class) have been named sensibly and if the right type of<br />

parameter passing has been used, you can often guess what a function does just by looking<br />

at its prototype. For example, the function TInt RFile::Write(const TDesC8&<br />

aBuffer) is the basic function for writing data to a file – you can even guess that TDesC8 is<br />

a type suitable for data buffers by looking at this signature. The TInt return is an error code,<br />

while the aBuffer parameter is a descriptor containing the data and is not modified by the<br />

function.<br />

Most of this is standard C++ fare. The exceptions are leaving functions, which we've already<br />

mentioned (and will explain fully in <strong>Chapter</strong> 6), and the naming conventions associated with<br />

DLLs. These are very important and aren't covered by C++ standards: I'll cover the<br />

significance of IMPORT_C later in the chapter.<br />

3.3.1 Function Parameters<br />

Each parameter's declaration gives valuable information about whether that parameter is to<br />

be used for input or output and a clue about whether the parameter is large or small. If a<br />

parameter is of basic type X, there are five possibilities for specifying it in a signature:

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

Saved successfully!

Ooh no, something went wrong!