【ARM】重新定义低级库函数,以便能够直接使用 C 库中的高级库函数
Redefining low-level library functions to enable direct use of high-level library functions in the C library
If you define your own version of __FILE, your own fputc() and ferror() functions, and the __stdout object, you can use all of the printf() family, fwrite(), fputs(), puts() and the C++ object std::cout unchanged from the library.
These examples show you how to do this. However, consider modifying the system I/O functions instead of these low-level library functions if you require real file handling.
You are not required to re-implement every function shown in these examples. Only re-implement the functions that are used in your application.
Retargeting printf()
#include <stdio.h>
struct __FILE
{
int handle;
/* Whatever you require here. If the only file you are using is */
/* standard output using printf() for debugging, no file handling */
/* is required. */
};
/* FILE is typedef'd in stdio.h. */
FILE __stdout;
int fputc(int ch, FILE *f)
{
/* Your implementation of fputc(). */
return ch;
}
int ferror(FILE *f)
{
/* Your implementation of ferror(). */
return 0;
}
void test(void)
{
printf("Hello world\n");
}
Note
Be aware of endianness with
fputc().fputc()takes anintparameter, but contains only a character. Whether the character is in the first or the last byte of the integer variable depends on the endianness. The following code sample avoids problems with endianness:extern void sendchar(char *ch);
int fputc(int ch, FILE *f)
{
/* example: write a character to an LCD */
char tempch = ch; // temp char avoids endianness issue
sendchar(&tempch); // sendchar(&ch) would not work everywhere
return ch;
}
Retargeting cout
File 1: Re-implement any functions that require re-implementation.
#include <stdio.h>
namespace std {
struct __FILE
{
int handle;
/* Whatever you require here. If the only file you are using is */
/* standard output using printf() for debugging, no file handling */
/* is required. */
};
FILE __stdout;
FILE __stdin;
FILE __stderr;
int fgetc(FILE *f)
{
/* Your implementation of fgetc(). */
return 0;
}
int fputc(int c, FILE *stream)
{
/* Your implementation of fputc(). */
}
int ferror(FILE *stream)
{
/* Your implementation of ferror(). */
}
long int ftell(FILE *stream)
{
/* Your implementation of ftell(). */
}
int fclose(FILE *f)
{
/* Your implementation of fclose(). */
return 0;
}
int fseek(FILE *f, long nPos, int nMode)
{
/* Your implementation of fseek(). */
return 0;
}
int fflush(FILE *f)
{
/* Your implementation of fflush(). */
return 0;
}
}
File 2: Print "Hello world" using your re-implemented functions.
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world\n";
return 0;
}
By default, fread() and fwrite() call fast block input/output functions that are part of the Arm stream implementation. If you define your own __FILE structure instead of using the Arm stream implementation, fread() and fwrite() call fgetc() instead of calling the block input/output functions.
【来源】
【ARM】重新定义低级库函数,以便能够直接使用 C 库中的高级库函数的更多相关文章
- Entity Framework 6 Recipes 2nd Edition(11-11)译 -> 在LINQ中调用数据库函数
11-11. 在LINQ中调用数据库函数 问题 相要在一个LINQ 查询中调用数据库函数. 解决方案 假设有一个任命(Appointment )实体模型,如Figure 11-11.所示, 我们想要查 ...
- Raspberry Pi3 ~ Eclipse中添加wiringPi 库函数
这篇是在博客园原创 转载注明出处啊 以前用单片机.STM32之类的时候都是在一个集成的开发环境下进行的 比如Keil.IAR等 那么linux下编程,eclipse是个不错的选择 关于树莓派的GPIO ...
- 编译在arm板上使用的sqlite3的静动态库
采用的是sqlite-autoconf-3080002.tar.gz 解压 tar xvf sqlite-autoconf-3080002.tar.gz 进入 cd sqlite-autoconf-3 ...
- 标准c库函数与Linux下系统函数库 区别 (即带不带缓冲区的学习)
我们都知道,C语言在UNIX/Linux系统下有一套系统调用(系统函数),比如文件操作open().close().write().read()等,而标准C语言的库函数中也有一套对文件的操作函数fop ...
- Entity Framework 中的Code First 中引入数据库函数
1,在项目中添加CodeFirstStoreFunctions包: Install-Package EntityFramework.CodeFirstStoreFunctions 2,注册注册函数,F ...
- 《Android进阶》之第一篇 在Java中调用C库函数
在Java代码中通过JNI调用C函数的步骤如下: 第一步:编写Java代码 class HelloJNI{ native void printHello(); native void printStr ...
- C#中List调用库函数sort进行升序排序
private void button1_Click(object sender, EventArgs e) { List<int> demo2 = new List<int> ...
- 如何调用.so动态库中的函数,如何把自己的函数导出为.so的动态库函数供别人调用
调用.so中的函数和平常的函数没有区别,只是在编译连接时加上-lxxxx就行了.要生成.so库,则编译时用下面的语句:gcc -shared -Wl,-soname,libmyfun.so -o li ...
- Arm Linux系统调用流程详细解析
Linux系统通过向内核发出系统调用(system call)实现了用户态进程和硬件设备之间的大部分接口. 系统调用是操作系统提供的服务,用户程序通过各种系统调用,来引用内核提供的各种服务,系统调用的 ...
- python快速教程-vamei
2016年10月26日 12:00:53 今天开始着手python的学习,希望能高效快速的学完! Python基础(上)... 7 实验简介... 7 一.实验说明... 8 1. 环境登录... 8 ...
随机推荐
- 华企盾DSC客户端连接服务器正常,控制台找不到客户端
1.首先客户端查一下策略状态,看一下客户端在哪个组,是否在回收站,或者无策略组: 2.查看一下数据库的CLIENT_GROUP_TABLE_表中是否有查出来的组,CLIENT_GROUP_TABLE_ ...
- Python subprocess 使用(二)
Python subprocess 使用(二) 本篇继续介绍subprocess的使用. 这里主要添加两个自己在工作过程中常用的两个小命令. 1: 获取顶层activity import subpro ...
- Javascript Ajax总结——XMLHttpRequest对象
Ajax技术能向服务器异步请求额外的数据,会带来更好的用户体验.Ajax技术核心:XMLHttpRequest对象(简称XHR).XHR为向服务器发送请求和解析服务器响应提供了流畅的接口.1.创建XM ...
- IDEA创建MyBatis项目--实现简单的查操作
IDEA创建MyBatis项目--实现简单的查操作 1.创建一个maven工程,不使用模板 2.通过maven加载Mybatis依赖包 在pom文件中导入maven坐标 <dependencie ...
- iMessage群发,iMessage群发功能,iMessage群发功能设计,iMessage群发系统
在数字通讯时代,群发消息已经成为我们日常生活中不可或缺的一部分,无论是商务.社交还是日常沟通,群发功能都大大提高了消息传递的效率和便利性. 而在众多的通讯软件中,iMessage无疑是其中的佼佼者,今 ...
- 文心一言大模型-function Calling的应用
"大模型的函数调用"(Large Model Function Calling)是一个涉及到在大型人工智能模型,如 GPT-4 或类似的高级深度学习模型中使用函数调用的概念.在这种 ...
- Sliver 二开准备
cs被杀麻了,最近打算看看一下sliver的源码进行一下二开,这篇是记录遇到的一些问题 编译sliver Windows下 官方说用MingW,但是我自己用他带的make不行, 下载make ...
- mysql的CRUD操作实现
插入语句(INSERT):一旦我们选择了要插入的字段, 我们就必须保证要插入的数值和选择的字段的个数,顺序,类型一致. 1:怎么插入一条数据: INSERT INTO 插入的表名称(列名1,列 ...
- Liquid 常用语法记录
一.什么是 Liquid Liquid 是一款专为特定需求而打造的模板引擎. Liquid 中有两种类型的标记:Output 和 Tag. Output 通常用来显示文本 {{ 两个花括号 }} Ta ...
- CSS3学习笔记引言
开始我们要来介绍css: CSS(全称为Cascading Style Sheets)是一种用于描述HTML.XML等文档样式的样式语言,它能够定义元素的显示方式,如字体.颜色.布局等. CSS可以把 ...