首页 技术 正文
技术 2022年11月12日
0 收藏 820 点赞 2,527 浏览 3505 个字

一开始运行出错,开启debug以后发现在push自定义对象的时候调试器提示找不到一个叫/XXX/XXXX/XXXX/libcstl-2.3.0/src/cstl_list_private.c</br>
而那个路径正是我进行安装的路径,安装完以后我把安装包给删除掉了,所以它找不到。这样的话,我们在一开始安装的时候就要注意最好先把tar.gz解压出来的文件夹放到特定文件夹,比如/usr/local/下,这样不会在安装完成后被误删,也比较方便查找。</br>
但是再次调试的时候却发现插入操作死在了调用_my_copy()函数那里,里面设置了一个int型临时变量i_temp用来作中间值方便调试,调试过程中发现i_temp成了一个非常小的负值。
但是直接调用_my_copy()是能正确运行的。</br>
鉴于程序呈现出这种尿性,我觉得应该是cstl它自己设计得不够健壮。。。不然实在是说不通程序会死在_my_copy()函数那里。
其实最后我发现copy函数形参里的cpv_source它的地址为0x1,明显就不可能。这个就关系到cstl对list的内部实现了,不想再深入去了解,暂时到此为止。
最后还是照惯例贴个代码:

 /*
* new_test_for_ctsl_selfType.c
*
* Created on: Mar 21, 2014
* Author: nerohwang
*/
#include<stdio.h>
#include<stdlib.h>
#include<cstl/clist.h>
#include<assert.h>
/*Initlizing a user-defined type ,use
* func type_register(1,2,3,4,5) first.
* 1.type: user-defined type
* 2.ufun_init: init function
* 3.bfun_copy: copy function
* 4.bfun_less: less-comparison function
* 5.ufun_destroy: destroy function bool_t type_register(
type,
unary_function_t ufun_init,
binary_function_t bfun_copy,
binary_function_t bfun_less,
unary_function_t ufun_destroy
);
*
*/
typedef struct user_defined_type
{
int i_first;
int i_second;
}myType; static void _my_init(const void* cpv_input,void* pv_output)
{
assert(cpv_input != NULL);
((myType*)cpv_input)->i_first = ;
((myType*)cpv_input)->i_second = ;
*((bool_t*)pv_output) = true;
} static void _my_copy(const void* cpv_dest,const void* cpv_source,void* pv_output)
{
assert(cpv_dest != NULL && cpv_source != NULL);
int i_temp = ((myType*)cpv_source)->i_first;
((myType*)cpv_dest)->i_first = i_temp;
i_temp = ((myType*)cpv_source)->i_second;
((myType*)cpv_dest)->i_second = i_temp;
*((bool_t*)pv_output) = true;
} static void _my_destroy(const void* cpv_input,void* pv_output)
{
assert(cpv_input != NULL);
((myType*)cpv_input)->i_first = ;
((myType*)cpv_input)->i_second = ;
*((bool_t*)pv_output) = true;
} static void _my_less(const void* cpv_first, const void* cpv_second,void* pv_output)
{
assert(cpv_first != NULL && cpv_second != NULL);
*((bool_t*)pv_output) = (((myType*)cpv_first)->i_first < ((myType*)cpv_second)->i_first)?true:false;
} int main(int argc,char* argv[])
{
list_t* pList = create_list(myType);
list_iterator_t i_it;
list_iterator_t my_it;
printf("Before type register:\n");
if(pList == NULL){
printf("Creation of myType failed!\n");
}else{
printf("Creation of myType succeeded!\n");
}
type_register(myType,_my_init,_my_copy,_my_less,_my_destroy); pList = create_list(myType);
printf("After type register:\n");
if(pList != NULL){
printf("Creation of myType succeeded!\n");
}else{
printf("Creation of myType failed!\n");
} //just a simple test.
myType my_first;
my_first.i_first = ;
my_first.i_second = ;
printf("first :one-> %d,sec-> %d\n",my_first.i_first,my_first.i_second); myType my_second; //default myType my_third;
my_third.i_first = ;
my_third.i_second = ; list_t* pList_i = create_list(int);
if(pList_i == NULL){
printf("Creation of int list failed!\n");
}
list_init(pList_i);
list_push_back(pList_i,);
list_push_back(pList_i,);
list_push_back(pList_i,);
printf("Now we have %d int-var in our list\n",list_size(pList_i));
for(i_it = list_begin(pList_i);!iterator_equal(i_it,list_end(pList_i));i_it = iterator_next(i_it))
{
printf("%d\t",*(int*)iterator_get_pointer(i_it));
}
printf("\n"); bool_t b_temp;
_my_copy((void*)&my_second,(void*)&my_first,(void*)&b_temp);
printf("Second :one-> %d,sec-> %d\n",my_second.i_first,my_second.i_second); printf("break point\n");
list_init(pList);
list_push_back(pList,my_second);
my_it = list_begin(pList);
printf("Second myType: one-> %d , sec->%d\n",((myType*)iterator_get_pointer(my_it))->i_first,\
((myType*)iterator_get_pointer(my_it))->i_second); printf("break point\n");
list_push_back(pList,my_first);
list_push_back(pList,my_third);
printf("Now we have %d obj in our list\n",list_size(pList));
return ; }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290