examples/after/source1.cpp
author William Roberts <williamr@symbian.org>
Mon, 22 Mar 2010 21:41:09 +0000
changeset 0 fe474e3b08fb
permissions -rw-r--r--
Created the examples directory, containing components called "before" and "after" The before directory is a component which illustrates typical issues that GCC has with the Symbian source code. Compiling this component (sbs -b bld.inf -k -c armv5_udeb_gcce4_4_1) will produce multiple errors, hence the use of "-k" to keep going. The after directory is the same component with fixes applied - compiling in the after directory should produce no errors. The aim is to keep the code very closely aligned to the before component, so that they can be compared with visual diff tools such as Beyond Compare. Sometimes it's valuable to be able to compile this code with the default production compiler, (currently RVCT 2.2) so the MMP files will switch the name of the generated executable if a different compiler is used.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     1
// Copyright (c) 2010 Symbian Foundation Ltd.
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     2
// All rights reserved.
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     3
// This component and the accompanying materials are made available
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     5
// which accompanies this distribution, and is available
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     7
//
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     8
// Initial Contributors:
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
     9
// Symbian Foundation - Initial contribution
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    10
// 
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    11
// Description:
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    12
// Examples of things which GCC does not like in the Symbian codebase.
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    13
// See the corresponding file in "after" for the preferred way to do it
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    14
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    15
// Over-qualified class names
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    16
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    17
#include "example_classes.h"
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    18
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    19
TClass1::TClass1(int a, int b)
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    20
	: iA(a), iB(b)
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    21
	{}
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    22
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    23
int TClass1::Average()
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    24
	{
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    25
	return (iA+iB)/2;
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    26
	}
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    27
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    28
int helper1(int a)
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    29
	{
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    30
	TClass1 c(a,11);
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    31
	return c.Average();
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    32
	}
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    33
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    34
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    35
//-------------------------
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    36
// Helper function to avoid things being optimised away
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    37
int source1(void)
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    38
	{
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    39
	extern int unknown(void);
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    40
	return helper1(unknown());
fe474e3b08fb Created the examples directory, containing components called "before" and "after"
William Roberts <williamr@symbian.org>
parents:
diff changeset
    41
	}