A tiny C-like library(类C语言的小库) A library usually starts out as a collection of functions, but if you 每一个库通常都会以一组函数开头,不过要是你用过第三方的库函数后, have used third-party C libraries you know there's usually more to 就会知道在C库函数中,通常会有更多的有用东西,毕竟生活中不仅仅只是行为,动作, it than that because there's more to life than behavior, actions, and 与方法。 functions. There are also characteristics (blue, pounds, texture, 除了上述以外,通常还会有一些特性(如:磅,蓝色,质地结构与亮度) luminance), which are represented by data. And when you start to 这些都会以数据表示出来。 deal with a set of characteristics in C, it is very convenient to clump 于是,在C语言中,在处理那些特性时,将它们组合在一个结构体中会很是方便的, them together into a struct, especially if you want to represent 这种情况在你想用结构体来表达多个类似的事物时更是如此。 more than one similar thing in your problem space. Then you can 这样,你就可以为每一个处理对象创建一结构体的变量。 make a variable of this struct for each thing. Thus, most C libraries have a set of structs and a set of functions 以这此思路,在大多数C语言库中会有一组结构体,并另有一组函数与之相应 that act on those structs. As an example of what such a system 作为上面所述原理的一个实例,我们现在考虑编程时经常用到的一个有用工具, looks like, consider a programming tool that acts like an array, but 这个工具用起来有点像数组,不过当运行创建时,它的大小会随时改着需要而改变。 whose size can be established at runtime, when it is created. I'll call 我们在此称之为“CStash”。虽说这是用C++写的,不过在C语言中它也有相同的形式。 it a CStash. Although it's written in C++, it has the style of what you'd write in C: //: C04:CLib.h // Header file for a C-like library // An array-like entity created at runtime typedef struct CStashTag { int size; // Size of each space int quantity; // Number of storage spaces int next; // Next empty space // Dynamically allocated array of bytes: unsigned char* storage; } CStash; void initialize(CStash* s, int size); void cleanup(CStash* s); int add(CStash* s, const void* element); void* fetch(CStash* s, int index); int count(CStash* s); void inflate(CStash* s, int increase); ///:~ A tag name like CStashTag is generally used for a struct in case 在需要在结构体内部对其部引用时,像CStashTag这样的标签通常会用在结构体中 you need to reference the inside itself. For example, when 经常会用到。 creating a linked list (each element in your list contains a pointer to 例如,当创建一个链表时,我们会需要一个指针用来指向下一个结构体变量, the next element), you need a pointer to the next struct variable, so 所以就会需要一种方式来在结构体判断这个指针的属性。 you need a way to identify the type of that pointer within the body. Also, you'll almost universally see the typedef as shown 就像上面CStash中所看到的那样,你也会在C库的每一个结构体定义中经常看到“typedef”关键字 above for every struct in a C library. This is done so you can treat 这样做是为了在应用时可以把结构体当作一个新的类型并像如下方式定义变量“CStash A, B, C;” the struct as if it were a new type and define variables of that like this: CStash A, B, C;
详细解决方案
相关解决方案
- 关于Nokia MMS Library 包包 发彩信的有关问题,请大侠们拔刀相助
- MyEclipse8.5 java.lang.UnsatisfiedLinkError: no license in java.library.path,该如何解决
- SonyEricsson_W800 Couldn't load zayitlib.dll library?解决思路
- No tag library could be found with this URI解决办法
- Eclipse导入工程后,XDoclet异常:Missing library: xdoclet-1.2.1.jar. Select the home direc
- LINQ to sQL:业务层多个Class Library,or 只用一个?该如何解决
- 企业库的优缺点?Enterprise Library,该如何解决
- enterprise library,该怎么解决
- MSDN Library 2003中文版3CD,要的快上载啊
- 大家来BT上载Microsoft.MSDN.Library.October.2004.DVD-QUANTUM
- magaView.HasMonth = db.Library.GroupBy(a => a.TimeBook.Month).Select(a => a.Key),该怎么处理
- 关于Enterprise Library 4.1的安全跟错误处理
- Enterprise Library 5连接DB2,该怎么解决
- 关于Enterprise Library 2.0的用法,该如何解决
- Enterprise Library 2.0 连接 access2003 Web.Config配置有关问题
- 使用 DataAccessApplicationBlock好? 还是使用 Enterprise Library 中的数据库访问助手类好?该如何处理
- 求教enterprise library -data access application block的有关问题
- (郁闷-高手路过请进)求教关于Excel 11.0 Object Library 的使用方法(asp.net+C#),该怎么解决
- Enterprise Library 2.0中怎么设置SQL命令超时
- Enterprise Library 2.0 怎么按照天来写日子
- 关于Enterprise Library 2.0 怎么引用
- 是这样写吗? Library.Take(count).Where(a => a.Status==status)
- Blackberry 下怎么使用第三方 Library (jar)
- DB2 ERROR: no db2jcct2 in java.library.path解决思路
- DB2 ERROR: no db2jcct2 in java.library.path解决方案
- 关于“The type * is not accessible due to restriction on required library”有关问题的解决
- 【转】关于“The type * is not accessible due to restriction on required library”有关问题的
- Can't open shared library 'spider.dll' (errno: 零 )
- Tiny Core Linux 3.3 公布,10兆Linux
- Tiny Core Linux 3.3 发布,10兆Linux解决思路