01.12.2014 Views

RealView Compilation Tools Developer Guide - ARM Information ...

RealView Compilation Tools Developer Guide - ARM Information ...

RealView Compilation Tools Developer Guide - ARM Information ...

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.

混 合 使 用 C、 C++ 和 汇 编 语 言<br />

从 C 或 汇 编 语 言 调 用 C++<br />

示 例 5-22、 示 例 5-23 和 第 5-29 页 的 示 例 5-24 中 的 代 码 说 明 如 何 从 C 或 汇 编 语<br />

言 调 用 非 静 态 、 非 虚 的 C++ 成 员 函 数 。 可 以 使 用 编 译 程 序 的 汇 编 程 序 输 出 来 查<br />

找 已 延 伸 的 函 数 名 。<br />

示 例 5-22 调 用 C++ 成 员 函 数<br />

struct T {<br />

T(int i) : t(i) { }<br />

int t;<br />

int f(int i);<br />

};<br />

int T::f(int i) { return i + t; }<br />

// Definition of the C++ function to be called from C.<br />

extern "C" int cfunc(T*);<br />

// declaration of the C function to be called from C++<br />

int f() {<br />

T t(5);<br />

return cfunc(&t);<br />

}<br />

// create an object of type T<br />

示 例 5-23 定 义 C 函 数<br />

struct T;<br />

extern int _ZN1T1fEi(struct T*, int);<br />

/* the mangled name of the C++ */<br />

/* function to be called */<br />

int cfunc(struct T* t) {<br />

/* Definition of the C function to be called from C++. */<br />

return 3 * _ZN1T1fEi(t, 2); /* like '3 * t->f(2)' */<br />

}<br />

5-28 © 2002、 2003 <strong>ARM</strong> Limited 版 权 所 有 。 保 留 所 有 权 利 。 <strong>ARM</strong> DUI 0203BSC

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

Saved successfully!

Ooh no, something went wrong!