Monday, July 20, 2015

Charizing Operator (#@) Does Not Work On MAC OSX

 #include <iostream>  
 using std::cout;  
 using std::endl;  
 #define Charizing(x) #@x  
 int main()  
 {  
   cout << Charizing(a) << endl;  
   cout << Charizing(b1) << endl;  
 }  
First, let's study above program. The output is
a
25137

Basically, Charizing(x) encloses the parameter x with single quotation mark and treats it as a character. That's why Charizing(a) returns a. However, when x is not a character, the output is some strange number. I guess the number is converted from type of parameter to char.

However, the above program is not compilable in Xcode. The error is '#' is not followed by a macro parameter.

As far as I know, Stringizing operator (#) and Token-pasting operator (##) work fine on Xcode, except Token-pasting operator (##). According to MSDN, Token-pasting operator (##) is a Microsoft specific. This is why it is not supported in Xcode.

To fix the program to work on both Windows and MAC OSX, we can first convert the parameter x to string and then get the first character. We suppose that x always contains one character with "#x[0]".
 #include <iostream>  
 using std::cout;  
 using std::endl;  
 #define Charizing(x) #x[0]  
 int main()  
 {  
   cout << Charizing(a) << endl;  
   cout << Charizing(b1) << endl;  
 }  
Thus,  we can remember #@x is equal to #x[0], assume that x is a one-char string.


Monday, July 13, 2015

Token-Pasting Operator (##) does not concat String as I expect




Let's study below example


#include
using std::cout;
using std::endl;


#define STRINGIFY2( x) #x
#define STRINGIFY(x) STRINGIFY2(x)

#define A1 a2
#define B1 b2

#define concat2(x, y, z) x ## y z
#define concat(x,y, z) concat2(x,y, z)
int main()
{
    cout << STRINGIFY(concat2(A1, B1, A1)) << endl;
    cout << STRINGIFY(concat(A1, B1, A1)) << endl;
    
}

The output is
A1B1 a2
a2b2 a2

According to MSDN, "If a formal parameter in a macro definition is preceded or followed by the token-pasting operator, the formal parameter is immediately replaced by the unexpanded actual argument. Macro expansion is not performed on the argument prior to replacement". Thus, in the function concat2, x and y are not expanded while z is expanded. Therefore, the first line output is "A1B1 a2. Note that the space between x and y is removed. On the other hand, the function concat calls concat2 and 3 arguments, x, y, and z are computed first and send to concat2. Therefore, the output is "a2b2 a2".


Income Tax Rate in Singapore

Income tax rates depend on an individual's tax residency status. You will be treated as a tax resident for a particular Year of Assessment (YA) if you are a : 
  1. Singapore Citizen who normally resides in Singapore except for temporary absences; or
  2. Singapore Permanent Resident (SPR) who has established your permanent home in Singapore; or
  3. Foreigner who has stayed / worked in Singapore (excludes director of a company) for 183 days or more in the previous year. i.e. the year before the YA.
Otherwise, you will be treated as a non-resident of Singapore for tax purposes.

Resident Tax Rates

For YA 2012 to YA 2016

Chargeable Income
Income Tax Rate (%)
Gross Tax Payable ($)
First $20,000
Next $10,000
0
2
0
200
First $30,000
Next $10,000
-
3.50
200
350
First $40,000
Next $40,000
-
7
550
2,800
First $80,000
Next $40,000
-
11.5
3,350
4,600
First $120,000
Next $ 40,000
-
15
7,950
6,000
First $160,000
Next $ 40,000
-
17
13,950
6,800
First $200,000
Next $120,000
-
18
20,750
21,600
First $320,000
Above $320,000
-
20
42,350

Resident Tax Rates

For YA 2012 to YA 2016

Chargeable Income
Income Tax Rate (%)
Gross Tax Payable ($)
First $20,000
Next $10,000
0
2
0
200
First $30,000
Next $10,000
-
3.50
200
350
First $40,000
Next $40,000
-
7
550
2,800
First $80,000
Next $40,000
-
11.5
3,350
4,600
First $120,000
Next $ 40,000
-
15
7,950
6,000
First $160,000
Next $ 40,000
-
17
13,950
6,800
First $200,000
Next $120,000
-
18
20,750
21,600
First $320,000
Above $320,000
-
20
42,350

Tax Rates for Non-Residents

Taxes on Employment Income

The employment income of non-residents is taxed at flat rate of 15% or the progressive resident tax rates (see table above), whichever is a higher tax amount.

Taxes on Director's fee, Consultation fees and All Other Income

Director's fees, consultation fees and all other income, are generally taxed at 20%.

From YA 2017 New!

The tax rates for non- resident individuals (except certain reduced final withholding tax rates) will be raised to 22% from YA 2017. This is to maintain parity between the tax rates of non-resident individuals and the top marginal tax rate of resident individuals.
Type of Income
Non-resident individual tax rate / withholding tax rate from YA 2017
(a)
Director's remuneration 
22%
(b)
Income derived from activity as a non-resident professional (consultant, trainer, coach, etc) 
15% of gross income or 22% of net income

(c)
Income derived from activity as a non-resident public entertainer (artiste, musician, sportsman, etc)
10% concessionary rate (No change)


(d)
Other income e.g. property rental income
22%
(e)
SRS withdrawal by a non-citizen SRS member
22%
(f)
Interest, royalty etc 
Reduced final withholding tax rate (subject to conditions) as follows:
Interest: 15%
Royalty: 10%
OR
22% if reduced final withholding tax rate is not applicable.

(according to IRAS, all the information is copied on 26 Jul 2015)