Chapter Fifteen : Portability

EXAMPLE 15.1 page no : 172

In [1]:
c = -100;
if (c < 0):
    pass

EXAMPLE 15.2 page no : 173

In [2]:
class BasicAttrType:
    counterGauge = 0x1000
    counterPeg = 0x2000
    conterAcc = 0x3000
    


t = BasicAttrType.counterGauge
print t
4096

EXAMPLE 15.3 page no : 173

In [3]:
a = ''
print a

example 15.5 page no : 174

In [4]:
result = 1234 * 567
print result
699678

Example 15.6 page no : 175

In [5]:
import math # python has only one way to importing file.
from math import *

exmaple 15.7 page no : 176

In [6]:
 
#   import inc.MyFile
#   import inc.MyFile

#   import gui.xinterface
Out[6]:
'\nexmaple 15.7 page no : 176\nDirectory names in include directives\nNote : python has . operator to import a file from directory\n'

EXAMPLE 15.8 page no : 176

In [7]:
import math

EXAMPLE 15.9 page no : 178

In [8]:
class PersonRecord:
    ageM = ''
    phoneNumberM = 0
    nameM = ''

EXAMPLE 15.10 page no : 178

In [9]:
def stepAndConvert(a,n):
    b = a + str(n) # step n chars ahead
    return b # NO: Dangerous cast of const char* to int*


data = "abcdefghijklmnop"
anInt = 3;
i = stepAndConvert(data, anInt)
print i
abcdefghijklmnop3

EXAMPLE 15.11 page no : 179

In [10]:
INT_MIN = -2147483648
INT_MAX = 2147483647
UINT_MAX = 4294967295
i = 42
ui  = 2222222242;
j = i - ui;
print j
-2222222200

EXAMPLE 15.12 page no : 180

In [11]:
zero = 0;
one = 1;
minusOne = zero - one;
print minusOne
result = one + minusOne;
print result
-1
0

EXAMPLE 15.13 page no : 180

In [2]:
#pid1 = fork(); # NO: should use pid_t

#pid2 = fork();

EXAMPLE 15.14 page no : 181

In [13]:
famousClimber = "Edmund Hillary"; # Uses Emc as prefix
print famousClimber
Edmund Hillary

EXAMPLE 15.15 page no : 183

In [14]:
class EmcArray:
    def __init__(self,size):
        pass

EXAMPLE 15.16 page no : 183

In [15]:
false = 0;
true = 1;

EXAMPLE 15.17 page no : 184

In [5]:
"""
i = 0;
for i in range(last()):
    pass

for i in range(first()):
    pass
    """
Out[5]:
'\ni = 0;\nfor i in range(last()):\n    pass\n\nfor i in range(first()):\n    pass\n    '

EXAMPLE 15.18 page no : 185

In [1]:
def emcMax(a,  b):
    if a>b:
        return a
    return b

def foo(i,j):
    m = emcMax(i, j); # usage of emcMax

q = 0 # usage of class EmcQueue<int> and
s = 0 # EmcQueue<int>:s default constructor

EXAMPLE 15.19 page no : 186

In [2]:
class EmcQueue:
    pass

EXAMPLE 15.20 page no : 187

In [3]:
class DangerousString:
    def __init__(self,cp):
        pass

    def char(self):
        pass

example 15.22 page no : 189

In [4]:
def main(self):
    return 0

EXAMPLE 15.23

In [ ]:
func(f1(), f2(), f3()) # f1 may be evaluated before f2 and f3,
# but don't depend on it!

EXAMPLE 15.24 page no : 189

In [6]:
a = [0,0,0]
i = 0
a[i] = i;
i += 1
print i 
1
In [ ]: