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万条数据配置好的电脑几秒钟就完成了,那是 ...
随机推荐
- Docker修改时区
简介 docker容器打日志时间滞后8小时 方法 启动时修改时区 Docker修改默认时区 已启动的容器修改时区 进入容器docker exec -i -t [CONTAINNER] /bin/bas ...
- 160308、java排序(形如1.1、1.2.1)
package com.rick.sample; import java.util.ArrayList; import java.util.Collections; import java.uti ...
- Apache 配置ArcGIS server/portal 反向代理
背景 处于安全,负载均衡,访问加速等原因会对服务器启用反向代理.arcgis for server的默认的访问地址为http://server:6080/arcgis.这个时候端口和实例名都暴露了.可 ...
- Newman语法参数
npm install -g newman npm install -g newman-reporter-html newman run XXX.json -k -r html --reporter- ...
- python和shell之间变量的相互调用
python -> shell: 1.环境变量 2.字符串连接 3.通过管道 import os var=’123’ os.popen(’wc -c’, ’w’).write(var) 4.通过 ...
- PHP json_encode自动转码的问题
用PHP的json_encode处理中文的时候, 中文会被编码成类似于"\u5f20\u4e09"的格式,例如: <?php $arr = array('张三','李四'); ...
- 新建虚拟机与本机ping不通(一招解决)
初始新建虚拟机或者复制虚拟机后,发现虚拟机能ping通内外网,但是本机无法ping通虚拟机,xshell也无法连接虚拟机 这时候就很头疼了,因为要上传很多文件到虚拟机上面 解决办法: 1.关闭虚拟机后 ...
- HTML5中Video和Audio
相关属性 src属性 该属性指定媒体数据的URL地址. autoplay属性 在该属性中指定是否在页面加载后自动播放,使用方法: <video src="test.mov" ...
- android 弹出带按钮的对话框
package com.example.helloworld; import android.os.Bundle;import android.app.Activity;import android. ...
- 微信小程序组件action-sheet
操作反馈action-sheet:官方文档 Demo Code: Page({ data: { actionSheetHidden: true, actionSheetItems: ['item1', ...