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.5 在 C++ 中 使 用 C 头 文 件<br />

本 节 描 述 如 何 在 C++ 代 码 中 使 用 C 头 文 件 。 从 C++ 调 用 C 头 文 件 之 前 ,C 头 文<br />

件 必 须 包 含 在 extern "C" 命 令 中 。<br />

5.5.1 包 括 系 统 C 头 文 件<br />

要 包 括 标 准 的 系 统 C 头 文 件 , 如 stdio.h, 不 必 进 行 特 殊 操 作 。 标 准 C 头 文 件 已<br />

经 包 含 适 当 的 extern "C" 命 令 。 例 如 :<br />

#include <br />

int main()<br />

{<br />

... // C++ code<br />

return 0;<br />

}<br />

如 果 使 用 此 语 法 包 含 头 文 件 , 则 所 有 库 名 都 放 在 全 局 命 名 空 间 中 。<br />

C++ 标 准 指 定 可 通 过 特 定 的 C++ 头 文 件 获 取 C 头 文 件 的 功 能 。 这 些 文 件 与 标 准<br />

C 头 文 件 一 起 安 装 在 install_directory\RVCT\Data\2.0\build_num\platform\include 中 ,<br />

可 以 用 常 规 方 法 进 行 引 用 。 例 如 :<br />

#include <br />

int main()<br />

{<br />

... // C++ code<br />

return 0;<br />

}<br />

在 <strong>ARM</strong> C++ 中 , 这 些 头 文 件 中 包 含 (#include) C 头 文 件 。 如 果 使 用 此 语 法 包 含<br />

头 文 件 , 则 所 有 C++ 标 准 库 名 都 在 命 名 空 间 std 中 定 义 , 包 括 C 库 名 。 这 意 味<br />

着 必 须 使 用 下 列 方 法 之 一 来 限 定 所 有 的 库 名 称 。<br />

• 指 定 标 准 命 名 空 间 , 例 如 :<br />

std::printf("example\n");<br />

• 使 用 C++ 关 键 字 using 向 全 局 命 名 空 间 输 入 一 个 名 称 :<br />

using namespace std;<br />

printf("example\n");<br />

• 使 用 编 译 程 序 选 项 --using_std。<br />

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

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

Saved successfully!

Ooh no, something went wrong!