Keil中使用MicroLib,以及malloc 待我称王封你为后i 2022-05-31 02:08 442阅读 0赞 The C Standard Library (stdlib.h) contains a number of useful and common tools, including: * string conversion * pseudo-random sequence generation * dynamic memory management * environment * searching and sorting * integer arithmethics * multibyte characters * multibyte strings as well as some constants EXIT\_FAILURE EXIT\_SUCCESS MB\_CUR\_MAX NULL RAND\_MAX and type definitions div\_t ldiv\_t lldiv\_t size\_t More information about the C standard library is available at [cplusplus.com][] reference pages. The standard library and standard input/output (stdio.h) are implemented in libc, and this is the one library that is, by default, linked to when you compile C code; if you want use the math library, you must explicitly link it with \-lm, and using the pthread library requires \-lpthread, but you never need include \-lc if you require something in either stdlib.h or stdio.h. The MDK-ARM that comes with μVision does not have a complete implementation of the standard library, and that library is not included by default. Instead, they provide a package called Microlib that implements many of the features in the standard library. In order to include the Microlib, it is necessary to toggle a setting in the options, which you may select by either entering **Alt-F7** or selecting **Project→Options for Target 'Target name'** or the icon ![options.png][]. This will bring up the **Options for Target 'Target name'** dialog. Select the check box next to **Use MicroLIB** in the **Code Generation** panel, as shown in Figure 1. ![use_microlib.png][] Figure 1. The check box selection for using the MicroLIB. # Simple example # Now you can take your previous example project and now include stdlib.h at the top and replace the body of void main(void)with int main( void ) { int i, *array; SystemInit(); while ( 1 ) { array = (int *) malloc( N * sizeof( int ) ); for ( i = 0; i < N; ++i ) { array[i] = i; } free( array ); } } # Example using a linked list # This is a rather boring example, so let's have a little more fun. In the C tutorials, there is an example that [builds a singly linked list][]. In the source directory, you will find the header file and source file for this data structure. Save these in the same directory as your other source file for the project above. You will then need to add single\_list.c to the Group **Source code**. You do not have to add the header file to the group, but it must still exist in the same directory as the source file. You will now replace the source file with #include <LPC17xx.h> #include <stdlib.h> #include "single_list.h" #define N 100 int main( void ) { // All local variables must be declared here (C89) int r; single_list_t list; SystemInit(); while ( 1 ) { // If the list is empty, add something to it. // If the list is full (size == N), remove something from it. // Otherwise, flip a coin as to whether or not something should // be added or removed. switch( list.size ) { case 0: single_list_push_front( &list, rand() ); break; case N: single_list_pop_front( &list ); break; default: r = rand(); if ( r & 1 ) { single_list_push_front( &list, r ); } else { single_list_pop_front( &list ); } } } } # What's next? # Next, if you are in the laboratory, you may want to create a project that prints to the liquid-crystal dispaly (LCD): see [Hello world!][Hello world]. Alternatively, if you want to see a real-time memory allocator where all allocations and de-allocations have a Θ(1) run time (good for Project 2), see [Dynamic memory allocation][]. 转自: [http://blog.csdn.net/cenzmin/article/details/52169763][http_blog.csdn.net_cenzmin_article_details_52169763] [cplusplus.com]: http://www.cplusplus.com/reference/cstdlib/ [options.png]: https://ece.uwaterloo.ca/~dwharder/icsrts/Keil_board/MicroLIB/images/options.png [use_microlib.png]: https://ece.uwaterloo.ca/~dwharder/icsrts/Keil_board/MicroLIB/images/use_microlib.png [builds a singly linked list]: https://ece.uwaterloo.ca/~dwharder/icsrts/C/11/ [Hello world]: https://ece.uwaterloo.ca/~dwharder/icsrts/Keil_board/Hello_world/ [Dynamic memory allocation]: https://ece.uwaterloo.ca/~dwharder/icsrts/Keil_board/dynamic/ [http_blog.csdn.net_cenzmin_article_details_52169763]: http://blog.csdn.net/cenzmin/article/details/52169763
相关 C语言中Malloc的使用 malloc函数: 原型:extern void \malloc(unsigned int num\_bytes); 用法:\include <malloc.h> 功能 布满荆棘的人生/ 2022年11月13日 15:30/ 0 赞/ 204 阅读
相关 KEIL使用教程——KEIL常用配置技巧 首先,介绍一些优秀的大佬整理的教程,首推黄工整理的的:[Keil系列教程][Keil] 非常非常全面! Configuration打开方法 点击主界面右上方的扳手按钮 港控/mmm°/ 2022年10月22日 11:58/ 0 赞/ 834 阅读
相关 KEIL使用教程——KEIL常用配置技巧 首先,介绍一些优秀的大佬整理的教程,首推黄工整理的的:[Keil系列教程][Keil] 非常非常全面! Configuration打开方法 点击主界面右上方的扳手按钮 心已赠人/ 2022年10月22日 10:52/ 0 赞/ 847 阅读
相关 keil应用小贴士:microLIB 在keil (我用的是realview mdk3.11)建立ARM的工程时 其中有一项是选 use MicroLIB 由于对KEIL不是很熟悉,于是就查了查,得到了以下信 本是古典 何须时尚/ 2022年10月01日 04:40/ 0 赞/ 360 阅读
相关 Keil中使用MicroLib,以及malloc The C Standard Library (stdlib.h) contains a number of useful and common tools, includin 待我称王封你为后i/ 2022年05月31日 02:08/ 0 赞/ 443 阅读
相关 Keil MDK 使用malloc()&free(),stm32简单测试可用 1.8.9 Using malloc() when exploiting the C library If heap support is required for ba 爱被打了一巴掌/ 2022年05月31日 02:08/ 0 赞/ 384 阅读
相关 Keil中的USE MicroLib说明 出处:[https://www.cnblogs.com/zyqgold/p/6114637.html][https_www.cnblogs.com_zyqgold_p_6114 忘是亡心i/ 2022年05月29日 09:15/ 0 赞/ 219 阅读
相关 malloc.h头文件以及malloc函数 malloc.h,[动态存储][Link 1][分配函数][Link 2]头文件,当对内存区进行操作时,调用相关函数.。 malloc函数是一种分配长度为num\_bytes 「爱情、让人受尽委屈。」/ 2022年05月19日 12:27/ 0 赞/ 436 阅读
相关 keil中使用Astyle格式化你的代码的方法-keil4 keil5通用 简介:在给RTT 提交代码,需要符合RT-Thread 的代码规范,本文简单介绍如何使用Astyle 格式化为符合RTT要求的代码风格。 关于Astyle Asty 待我称王封你为后i/ 2021年11月02日 07:26/ 0 赞/ 697 阅读
还没有评论,来说两句吧...