libcstl中的list没法插入自定义数据
一开始运行出错,开启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 ; }
libcstl中的list没法插入自定义数据的更多相关文章
- Effective Objective-C 2.0 — 第10条:在既有类中使用关联对象存放自定义数据
可以通过“关联对象”机制来把两个对象连起来 定义关联对象时可指定内存管理语义,用以模仿定义属性时所采用的“拥有关系”与“非拥有关系” 只有在其他做法不可行时才应选用关联对象,因为这种做法通常会引入难于 ...
- 用mybatis中的insert方法插入数据,返回值为1,但数据库却没有数据
刚才在写东西的时候,用mybatis中的 <insert id="add" parameterType="cn.entity.Computer"> ...
- Microsoft Azure 上的自定义数据和 Cloud-Init
自定义数据是什么? 客户经常询问如何才能在配置Microsoft Azure 虚拟机时插入脚本或其他元数据.在其他云中,这个概念通常称为用户数据.MicrosoftAzure 中也有一项类似的功 ...
- Apex 中插入更新数据的事件执行顺序
在使用 Apex 代码插入或更新数据的时候,若干事件会被按顺序执行.了解这些顺序可以提高调试程序的效率,也可以避免不必要的错误. 可以参考官方文档. 事件的执行顺序 从数据库中读取要更新的数据记录或初 ...
- sql 中的Bulk和C# 中的SqlBulkCopy批量插入数据 ( 回顾 and 粗谈 )
通常,我们会对于一个文本文件数据导入到数据库中,不多说,上代码. 首先,表结构如下. 其次,在我当前D盘中有个文本文件名为2.txt的文件. 在数据库中,可以这样通过一句代码插入. Bulk in ...
- GridView控件中插入自定义删除按钮并弹出确认框
GridView控件中插入自定义删除按钮,要实现这个功能其实有多种方法,这里先记下我使用的方法,以后再添加其他方法. 一.实现步骤 1.在GridView中添加模板列(TemplateField). ...
- SQL Server 2012中快速插入批量数据的示例及疑惑
SQL Server 2008中SQL应用系列--目录索引 今天在做一个案例演示时,在SQL Server 2012中使用Insert语句插入1万条数据,结果遇到了一个奇怪的现象,现将过程分享出来,以 ...
- 在mysql数据库中创建oracle scott用户的四个表及插入初始化数据
在mysql数据库中创建oracle scott用户的四个表及插入初始化数据 /* 功能:创建 scott 数据库中的 dept 表 */ create table dept( deptno int ...
- C#往SQLServer中插入大数据
以前插入大数据的时候都是一条一条的插入,由于电脑配置不行,有一次17万条数据用了半个小时才插入完成,那个蛋疼啊! 前面听杨中科老师的课,发现一个很好的东西,25万条数据配置好的电脑几秒钟就完成了,那是 ...
随机推荐
- LeetCode 笔记系列16.1 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]
题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...
- powerdesinger导出数据库说明文档
设置表结构要展示的属性,以及各个属性的展示列宽 不显示标题 右键单击items,选择format,然后Available栏中选择ListText选项卡,设置表格边框 保存为模板,Report-> ...
- 170309、MySQL存储引擎MyISAM与InnoDB区别总结整理
1.MySQL默认存储引擎的变迁 在MySQL 5.1之前的版本中,默认的搜索引擎是MyISAM,从MySQL 5.5之后的版本中,默认的搜索引擎变更为InnoDB. 2.MyISAM与InnoDB存 ...
- transform的妙用---实现div不定宽高垂直水平居中
transform的兼容性 transform的兼容性还是比较乐观的.IE9以下不兼容,IE9支持代替的-ms-transform属性不过只支持2D转换. 谷歌和Safari支持代替的-webkit- ...
- ELK basic---http://udn.yyuap.com/doc/logstash-best-practice-cn/filter/grok.html
http://blog.csdn.net/lgnlgn/article/details/8053626 elasticsearch学习入门 input {stdin{}}filter { grok { ...
- centos7 启动docker失败--selinux-enabled=false
centos7,执行完安装命令: yum install docker 执行启动命令: systemctl start docker ,报下面错误: Error starting daemon: ...
- 【题解】P5151 HKE与他的小朋友
[题解]P5151 HKE与他的小朋友 实际上,位置的关系可以看做一组递推式,\(f(a_i)=f(a_j),f(a_j)=f(a_t),etc...\)那么我们可以压进一个矩阵里面. 考虑到这个矩阵 ...
- JavaScript和jQuery的学习
还有12天就要回学校了,我的假期计划还能实现吗?在这12天里,需要把JavaScript和jQuery学完.我知道这两个技术对于前端网页开发非常重要.前期把HTML和CSS学完了,学的不是特别深,只是 ...
- 如何看MFC程序
一直以来 我都一个疑惑 如果看懂别人的MFC 程序. 今日忽然略有小悟. Q:MFC是啥? A:MFC是类库.. ************* Q :MFC 啥玩意类库? A;MFC 是封装API的类 ...
- 取得选中Grid的数据
var MergeAction = new Ext.Action({ text: '合并(选中两行)', handler: function () { if (grid.getSelectionMod ...