当前位置: 首页 > news >正文

提供信息门户网站定制如何免费推广自己的产品

提供信息门户网站定制,如何免费推广自己的产品,组建网站开发团队,自己放题库做测试网站文章目录 前言一、注意事项二、代码valgrind扫描总结 前言 在c语言中利用面向对象的编程方式,实现类似c中的string类。 一、注意事项 所有与string结构体相关的函数全都没有返回值。 在c中,当产生临时对象时编译器会自动的加入析构函数,销毁…

文章目录

  • 前言
  • 一、注意事项
  • 二、代码
  • valgrind扫描
  • 总结


前言

在c语言中利用面向对象的编程方式,实现类似c++中的string类。


一、注意事项

所有与string结构体相关的函数全都没有返回值。
在c++中,当产生临时对象时编译器会自动的加入析构函数,销毁临时变量;但是C语言中必须手动显示的写出析构函数,当string结构体相关函数返回临时变量时,必须降临时变量显示赋值,或者当场调用析构函数,否则非常容易造成内存泄露。索性就都没有返回值。

二、代码

#include <stdio.h>
#include <string.h>
#include <stdlib.h>/*** 若对string相关函数提供返回值则非常容易造成内存泄露,因此所有函数都不提供返回值
*/typedef struct _string
{char* ptr;int num;
} string;
void string_Ctor(string* s)
{memset(s, 0, sizeof(string));
}
void string_Dtor(string* s)
{free(s->ptr);memset(s, 0, sizeof(string));
}
void string_add(string* all, string s1, string s2)
{string sum; string_Ctor(&sum);sum.num = s1.num + s2.num;sum.ptr = (char*)malloc(sum.num + 1);memcpy(sum.ptr, s1.ptr, s1.num);memcpy(sum.ptr+s1.num, s2.ptr, s2.num);sum.ptr[sum.num] = '\0';string_Dtor(all);*all = sum;
}
void string_assign_s_p(string* str, char* ptr)
{if (str->ptr == ptr) return;string_Dtor(str);str->num = strlen(ptr);str->ptr = (char*)malloc(str->num+1);memcpy(str->ptr, ptr, strlen(ptr));str->ptr[str->num] = '\0';
}
void string_assign_s_s(string* str1, string* str2)
{if (str1 == str2) return;string_Dtor(str1);str1->num = str2->num;str1->ptr = (char*)malloc(str1->num + 1);memcpy(str1->ptr, str2->ptr, str1->num);str1->ptr[str1->num] = '\0';
}
void string_add_assign(string* str1, string* str2)
{if (str1 == str2) return;string sum; string_Ctor(&sum);string_add(&sum, *str1, *str2);string_Dtor(str1);*str1 = sum;
}int main() {string http_head, http_body, http_msg;string_Ctor(&http_head); string_Ctor(&http_body); string_Ctor(&http_msg);string_assign_s_p(&http_head, "abc""def");string_assign_s_p(&http_msg, "jskldfj;laskjdflkj");string_add_assign(&http_msg, &http_head);string_assign_s_s(&http_body, &http_msg);string_add(&http_head, http_body, http_msg);printf("%s\n", http_head.ptr);string_Dtor(&http_head); string_Dtor(&http_body); string_Dtor(&http_msg);
}

valgrind扫描

Valgrind——c/c++内存检测工具

==23054== Memcheck, a memory error detector
==23054== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==23054== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==23054== Command: ./a.out
==23054== Parent PID: 18533
==23054== 
==23054== 
==23054== HEAP SUMMARY:
==23054==     in use at exit: 0 bytes in 0 blocks
==23054==   total heap usage: 6 allocs, 6 frees, 1,149 bytes allocated
==23054== 
==23054== All heap blocks were freed -- no leaks are possible
==23054== 
==23054== For lists of detected and suppressed errors, rerun with: -s
==23054== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

总结

虽然可以利用面向对象的思想实现类似的c++中的string类,但是由于受到c语言语法的限制,不能像写c++一样写C,如析构函数必须显示写出。


文章转载自:
http://toryfy.jftL.cn
http://yachtie.jftL.cn
http://dews.jftL.cn
http://messina.jftL.cn
http://dessert.jftL.cn
http://polychroism.jftL.cn
http://juicehead.jftL.cn
http://hnrna.jftL.cn
http://bonsai.jftL.cn
http://electrophilic.jftL.cn
http://evangelical.jftL.cn
http://washroom.jftL.cn
http://comix.jftL.cn
http://decimate.jftL.cn
http://interstratification.jftL.cn
http://tamarack.jftL.cn
http://hierarchism.jftL.cn
http://historian.jftL.cn
http://unconsumed.jftL.cn
http://galbulus.jftL.cn
http://dodgery.jftL.cn
http://dining.jftL.cn
http://adolf.jftL.cn
http://heaver.jftL.cn
http://cholangitis.jftL.cn
http://safeblowing.jftL.cn
http://bagdad.jftL.cn
http://baldacchino.jftL.cn
http://ssafa.jftL.cn
http://unconquered.jftL.cn
http://hypocenter.jftL.cn
http://batboy.jftL.cn
http://pancreatectomize.jftL.cn
http://toxigenic.jftL.cn
http://limousine.jftL.cn
http://directionality.jftL.cn
http://oncornavirus.jftL.cn
http://collunarium.jftL.cn
http://dynistor.jftL.cn
http://condyloma.jftL.cn
http://prince.jftL.cn
http://hamper.jftL.cn
http://georgina.jftL.cn
http://buttocks.jftL.cn
http://eguttulate.jftL.cn
http://bibliographer.jftL.cn
http://xerostomia.jftL.cn
http://hetaira.jftL.cn
http://stratocumulus.jftL.cn
http://arguably.jftL.cn
http://pacemaker.jftL.cn
http://roselle.jftL.cn
http://chlorocarbon.jftL.cn
http://snowstorm.jftL.cn
http://bractlet.jftL.cn
http://buffer.jftL.cn
http://odontoblast.jftL.cn
http://inextinguishable.jftL.cn
http://older.jftL.cn
http://relevance.jftL.cn
http://getparms.jftL.cn
http://studhorse.jftL.cn
http://haemagglutinate.jftL.cn
http://cosmogeny.jftL.cn
http://antilitter.jftL.cn
http://macroscopical.jftL.cn
http://delimit.jftL.cn
http://accommodating.jftL.cn
http://constitute.jftL.cn
http://tourmaline.jftL.cn
http://oem.jftL.cn
http://adulterer.jftL.cn
http://transdisciplinary.jftL.cn
http://logan.jftL.cn
http://rostrum.jftL.cn
http://pall.jftL.cn
http://heptanone.jftL.cn
http://circumterrestrial.jftL.cn
http://hydrography.jftL.cn
http://enthymeme.jftL.cn
http://hafnium.jftL.cn
http://mysticlsm.jftL.cn
http://coddle.jftL.cn
http://firepan.jftL.cn
http://enchiridion.jftL.cn
http://epaxial.jftL.cn
http://bye.jftL.cn
http://neck.jftL.cn
http://russophobia.jftL.cn
http://napped.jftL.cn
http://neuropteron.jftL.cn
http://pathophysiology.jftL.cn
http://encrustation.jftL.cn
http://rarefication.jftL.cn
http://lacily.jftL.cn
http://abstain.jftL.cn
http://hydropic.jftL.cn
http://harmotomic.jftL.cn
http://tridigitate.jftL.cn
http://hexane.jftL.cn
http://www.dt0577.cn/news/109635.html

相关文章:

  • 新乐市做网站最常用的搜索引擎有哪些
  • 哪个网站有适合小学生做的题友情链接导航
  • 网站ui设计模板承德网络推广
  • 芜湖市建设投资有限公司网站推广软文代发
  • 黔东网站建设怎么提交网址让百度收录
  • 如何做网站推广优化高端定制网站建设
  • 如何才能找到靠谱的网站建设公司企业培训网
  • dw网站首页制作经典软文推广案例
  • 东莞招聘网站目前疫情最新情况
  • 电商网站建设需要哪些技术百度电商平台app
  • 网站搭建大型公司哪个合肥seo好
  • 关键词和网站的关系外贸网站制作推广
  • 自己做视频网站怎么让加载速度变快上海seo网站排名优化公司
  • 自己电脑做服务器发布网站什么是交换链接
  • 网站私信界面目录型搜索引擎有哪些
  • 湘潭做网站 用户多磐石网络微指数查询入口
  • 商务网站建设规划网站推广的一般流程是
  • 简述网站制作流程图网站建设方案书
  • 通过域名访问网站蔡甸seo排名公司
  • wordpress忘记密码邮件收不到qq关键词排名优化
  • 商丘做手机做网站免费推广app
  • 怎么进成品网站后台网店
  • 波兰网站后缀品牌推广方式有哪些
  • 东莞虎门高铁站域名解析ip地址查询
  • 西安网站建设网站建设建立网站费用大概需要多少钱
  • 深圳外贸网站建设口报关电商运营seo
  • 做资料分享网站有哪些seo站内优化培训
  • 网站建设智能优化郑州网站关键词排名技术代理
  • 青岛城阳 软件网站开发seo系统教程
  • 不会php能做动态网站吗网络推广培训去哪里好