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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

示 例 5-15 定 义 汇 编 语 言 函 数<br />

AREA Asm, CODE<br />

EXPORT asmfunc<br />

asmfunc<br />

LDR r1, [r0]<br />

ADD r1, r1, #5<br />

STR r1, [r0]<br />

MOV pc, lr<br />

END<br />

; the definition of the Asm<br />

; function to be called from C++<br />

从 C 调 用 C++<br />

示 例 5-16 和 示 例 5-17 显 示 如 何 从 C 调 用 C++。<br />

示 例 5-16 定 义 被 调 用 的 C++ 函 数<br />

struct S { // has no base classes or virtual functions<br />

S(int s) : i(s) { }<br />

int i;<br />

};<br />

extern "C" void cppfunc(S *p) {<br />

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

// The function is written in C++, only the linkage is C<br />

p->i += 5; //<br />

}<br />

示 例 5-17 在 C 中 声 明 并 调 用 该 函 数<br />

struct S {<br />

int i;<br />

};<br />

extern void cppfunc(struct S *p);<br />

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

int f(void) {<br />

struct S s;<br />

s.i = 2; /* initialize 's' */<br />

cppfunc(&s); /* call 'cppfunc' so it */<br />

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

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

Saved successfully!

Ooh no, something went wrong!