#define pr(a, b...) printf(a, b) /* (*A) */ #define pr(a, b...) printf(a, ##b) /* (*B) */ pr("Hello\n"); /* (*1) */ pr("Hello %s\n", "World"); /* (*2) */ pr("Hello %s %s\n", "My", "World"); /* (*3) */


GCC(C89)에서 사용할 수 있는 위의 두가지 macro는 언뜻 같아 보이지만 차이가 존재한다.
(*A) (*B) 모두 (*2)와 (*3) 같은 경우에서 정상적으로 잘 동작한다.
그런데, (*1)의 경우를 보면, 1은 macro에서 정의하고 있는 두번째 arguement가 없는 경우다. 즉 macro argument 'b'가 없다.
따라서 preprocessing결과를 생각해보면, (*A) (*B) 모두

printf(a, )

가 되어서 compile error가 나야 할 것 같은데, (*A)와 같이 정의하면, compile error가 발생하고, (*B)와 같이 정의하면 정상동작한다.
GCC spec.을 살펴보지 않았으나, 주의할 필요가 있어서 적어 둔다. (재미있지 않은가?)

[ g++ issue ]

g++-4.4 / g++-4.5 doesn't detect following case, but, g++-4.6 does.

< a.cpp >
---------

class P {
public:
    void a();
};

class A : public P {
public:
    void p();
};

void
P::a() {
    // 'const' quailifier' is discard here!
    static_cast<const A*>(this)->p();
}

void
A::p() {
    ;
}

int
main() {
    return 0;
}

=================== Test ======================
$ g++-4.5 a.cpp   <= OK.
$ g++-4.6 a.cpp
a.cpp: In member function ‘void P::a()’:
a.cpp:13:33: error: passing ‘const A’ as ‘this’ argument of ‘void A::p()’ discards qualifiers [-fpermissive]

The problem is some of Android codes still have above bugs in its code - ex. frameworks/base/libs/utils/RefBase.cpp.
So, even if Android source code was successfully compiled at g++-4.4 or g++4.5, it may be failed at g++-4.6 (for example, upgrading host OS)

[ cc/gcc issue ]

Compiling with gcc-4.6 raises following warings.

<command-line>:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]

In some component which uses '-Werror' option, this warning stops compilation.

[ Conclusion ]

So, you would better to use gcc/g++-4.4 instead of 4.6 when building Android, until above issues are resolved on Android baseline.
(ex. Ubuntu 11.10 as an Android host OS.)

+ Recent posts