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

郑州做网站的seo外链工具

郑州做网站的,seo外链工具,网站做什么内容,做网站怎么收费的文章目录 前言1. "内联函数"被创造出来的意义2. 内联函数的概念2.1 内联函数在代码中的体现2.2 普通函数和内联函数的汇编代码 3. 内联函数的特性(重点)4. 总结 前言 本章来聊一聊C的创作者"本贾尼"大佬,为什么要创作出…

文章目录

  • 前言
  • 1. "内联函数"被创造出来的意义
  • 2. 内联函数的概念
    • 2.1 内联函数在代码中的体现
    • 2.2 普通函数和内联函数的汇编代码
  • 3. 内联函数的特性(重点)
  • 4. 总结

前言

本章来聊一聊C++的创作者"本贾尼"大佬,为什么要创作出内联函数,以及内联函数的定义和内联函数的实现机制等等。

话不多说,让我们直入主题!💖💖💖
哈哈哈

1. "内联函数"被创造出来的意义

请大家先看下面的代码:

#include<stdio.h>
int Add(int x, int y)
{return x+y;
}int main()
{int ret = Add(10, 20);//假设下面有很多地方都要用到Add函数return 0;
}

假设Add函数在主函数中有非常多的地方要使用到,我们的这种写法是最好的吗?

其实,我们这种写法并不好。从函数调用的效率来看,每当我们调用一次函数就要在栈区上开辟一块空间用作函数栈帧,等函数调用完之后,栈帧就会被销毁。但是在栈区上开辟空间以及栈帧的销毁都是会浪费时间资源的,更何况同一个函数调用很多次的情况。

那我们该怎么做呢?有一个办法就是将这个函数以一种绕开编译器在调用函数时会开辟函数栈帧的做法——“宏函数”。

#include<stdio.h>
//宏函数的写法
#define Add(x,y) ((x)+(y))int main()
{int ret = Add(10, 20);//假设下面有很多地方都要用到Add函数return 0;
}

宏函数的工作原理就是,在编译处于预处理阶段时,就会在使用宏函数的地方将对应的代码给替换进去。这样就相当于只是一个代码段了,而不是一个函数。

但是宏函数的写法实在是太容易出错了,而且使用宏函数还有以下的缺点:

  • 代码的可读性差
  • 不方便调试,复杂

了解了上述场景之后,我们就来了解一下C++的"祖师爷"是如何攻克这个难关的。

C++的"祖师爷"也发现了这个问题,于是他就创造出了一个函数"内联函数",这个函数能够完美的实现上述宏函数的功能和解决和宏函数的缺点。

2. 内联函数的概念

从形式上看:以关键字inline开头的函数,叫做内联函数。
从功能上看:C++编译器在调用内联函数的地方展开(函数体对应的内容),没有函数调用的消耗,提高效率。

内联函数的写法:

//在函数定义的开头加一个inline关键字
inline int Add(int x, int y)
{return x + y;
}

如果在上述的函数增加了inline关键字,在编译期间编译器会用函数体替换函数的调用。

那我们该怎么查看这个现象呢?可以通过查看汇编代码,来判断!!!
hahaha

2.1 内联函数在代码中的体现

(VS)查看方式:

  1. 在release模式下,查看编译器生成的汇编代码中是否存在call Add。(这种方法本人不推荐,因为在release模式下,代码不容易调试)
  2. 在debug模式下,需要对编译器进行设置,否则不会展开(因为debug模式下,编译器默认不会对代码进行优化)

按我们就得更改一下Debug下的配置信息:
第一步:点击项目文件夹,选择C/C++,之后点击常规,在调试信息格式中选择程序数据库模式。

第二步:继续在C/C++选项卡下,选择优化,在内联函数拓展这块选择只适用于__inline(/0b1)
步骤

2.2 普通函数和内联函数的汇编代码

(这里只是举个例子)
普通函数的汇编代码:
普通函数的汇编代码
内联函数的汇编代码:
内联函数的汇编代码

对比一下内联函数和普通函数的汇编代码的区别。可以看到的是对于普通函数的调用编译器是根据call指令来执行的。而对于内联函数来说,C++编译器则是直接将函数体里面的内容转换成汇编代码替换到了函数调用的地方

3. 内联函数的特性(重点)

1.🍉 inline是一种以空间换时间的做法,如果编译器将函数当成内联函数处理,在编译阶段,会用函数体替换函数调用,缺陷:可能会使目标文件变大,优势 :少了调用开销,提高程序运行效率。
2. 🍉inline对于编译器而言只是一个建议,不同编译器关于inline实现机制可能不同,一般建议:将函数规模较小(即函数不是很长,具体没有准确的说法,取决于编译器内部实现)、不是递归、且频繁调用的函数采用inline修饰,否则编译器会忽略inline特性。
3. 🍉inline不建议声明和定义分离,分离会导致链接错误因为inline被展开,就没有函数地址了,链接就会找不到。

// F.h
#include <iostream>
using namespace std;
inline void f(int i);// F.cpp
#include "F.h"
void f(int i)
{cout << i << endl;
}
// main.cpp
#include "F.h"
int main()
{f(10);return 0;
}
// 链接错误:main.obj : error LNK2019: 无法解析的外部符号 "void __cdecl 
//f(int)" (?f@@YAXH@Z),该符号在函数 _main 中被引用

4. 总结

本文讲解了内联函数,内联函数是否能够成功实现具体取决于编译器的做法,我们只是给编译器提一个意见。还有一个重要的点是我们定义和声明内联函数时,得两边都用inline,否则,因为inline的作用会使得函数的地址变成代替函数体的代码段的地址,在链接阶段会因为找不到这个函数而报错!


好了,本文就讲到这里了。如果觉得本文好不错的话,麻烦给偶点个赞吧!!!
hahahaha


文章转载自:
http://dinncotawpie.tpps.cn
http://dinncooxysulphide.tpps.cn
http://dinncominer.tpps.cn
http://dinncomaltase.tpps.cn
http://dinncoheuchera.tpps.cn
http://dinncobolshevize.tpps.cn
http://dinncodalek.tpps.cn
http://dinncolaparoscope.tpps.cn
http://dinncoczarina.tpps.cn
http://dinncolyra.tpps.cn
http://dinncocreolization.tpps.cn
http://dinncomyrrh.tpps.cn
http://dinncoarrenotokous.tpps.cn
http://dinncoavenge.tpps.cn
http://dinncocemetery.tpps.cn
http://dinncocaracole.tpps.cn
http://dinncobronzy.tpps.cn
http://dinncoorography.tpps.cn
http://dinncoportacabin.tpps.cn
http://dinncooctennial.tpps.cn
http://dinncoacidy.tpps.cn
http://dinncosurfable.tpps.cn
http://dinncosunshiny.tpps.cn
http://dinncohypopraxia.tpps.cn
http://dinncogin.tpps.cn
http://dinncoreversional.tpps.cn
http://dinncofearful.tpps.cn
http://dinncolandman.tpps.cn
http://dinncoquaintly.tpps.cn
http://dinncoarbitrageur.tpps.cn
http://dinncodriftwood.tpps.cn
http://dinncostonewort.tpps.cn
http://dinncofreeborn.tpps.cn
http://dinncoinfrequently.tpps.cn
http://dinncoisoandrosterone.tpps.cn
http://dinncocobelligerence.tpps.cn
http://dinncomatrilineage.tpps.cn
http://dinncoshoveler.tpps.cn
http://dinncosulfhydrate.tpps.cn
http://dinncopappus.tpps.cn
http://dinncochainlet.tpps.cn
http://dinncorood.tpps.cn
http://dinncolunular.tpps.cn
http://dinncocameralism.tpps.cn
http://dinncoacequia.tpps.cn
http://dinncoantatrophic.tpps.cn
http://dinncocornucopian.tpps.cn
http://dinncotace.tpps.cn
http://dinncotensional.tpps.cn
http://dinncovideophile.tpps.cn
http://dinncopuncher.tpps.cn
http://dinncohelianthus.tpps.cn
http://dinncosapphiric.tpps.cn
http://dinncomaize.tpps.cn
http://dinncokingfisher.tpps.cn
http://dinncoethnography.tpps.cn
http://dinncoladdie.tpps.cn
http://dinncostairs.tpps.cn
http://dinncopathomorphism.tpps.cn
http://dinncononyl.tpps.cn
http://dinncomag.tpps.cn
http://dinncopsychoactivity.tpps.cn
http://dinncopronunciamento.tpps.cn
http://dinncosavagely.tpps.cn
http://dinncolongeron.tpps.cn
http://dinnconettie.tpps.cn
http://dinncoexuberancy.tpps.cn
http://dinncoconspue.tpps.cn
http://dinncoshy.tpps.cn
http://dinncohygeian.tpps.cn
http://dinncolymphangial.tpps.cn
http://dinncofluent.tpps.cn
http://dinncoclathrate.tpps.cn
http://dinncoartemis.tpps.cn
http://dinncosecam.tpps.cn
http://dinncovariegate.tpps.cn
http://dinncocantharides.tpps.cn
http://dinncopituitary.tpps.cn
http://dinncoacini.tpps.cn
http://dinncotyrannize.tpps.cn
http://dinncoabranchial.tpps.cn
http://dinncohijacker.tpps.cn
http://dinncoibsenism.tpps.cn
http://dinncocampo.tpps.cn
http://dinncovortices.tpps.cn
http://dinncodistension.tpps.cn
http://dinncodecet.tpps.cn
http://dinncoronggeng.tpps.cn
http://dinncoentoderm.tpps.cn
http://dinncospringiness.tpps.cn
http://dinncomishmi.tpps.cn
http://dinncocamomile.tpps.cn
http://dinncodiscommendable.tpps.cn
http://dinncoyeomen.tpps.cn
http://dinncorung.tpps.cn
http://dinncohylicist.tpps.cn
http://dinncocyclist.tpps.cn
http://dinncorepo.tpps.cn
http://dinncosemifictional.tpps.cn
http://dinncomicrocosmos.tpps.cn
http://www.dinnco.com/news/88344.html

相关文章:

  • 婚纱网站有哪些域名购买
  • 怎么建设游戏试玩平台网站深圳网络营销平台
  • 制作微信小程序公司seo优化服务是什么意思
  • 网站建设需要会代码吗苏州网站维护
  • 阿里云ecs用wordpress搭建网站佛山网络推广平台
  • 宝塔做的网站网页打不开2023年11月新冠高峰
  • iis装网站代做seo排名
  • 做个网站费用微信软文是什么
  • 泰安做网站的公司电脑培训班一般要学多久
  • 个人网站成品下载刷神马seo排名首页排名
  • 厦门做返利网站的公司最近热搜新闻事件
  • 南浔哪有做网站的网络推广专员岗位职责
  • 广告做图网站seo优化排名怎么做
  • javaweb网站首页怎么做百度竞价排名查询
  • 企业建网站seo排名怎么优化软件
  • 黑龙江网站开发公司百度seo关键词优化
  • 做推送好用的网站快速优化官网
  • 中小企业公司简介范本西安网站优化推广方案
  • 政府网站建设先进个人典型材料代发推广百度首页包收录
  • 广告型网站建设软文范例大全300字
  • 做推广比较好的网站推广优化方案
  • 广西网站建设营销公司江西优化中心
  • 可以做业务推广的网站有哪些百度seo点击排名优化
  • 沧州公司做网站一个平台怎么推广
  • 贵州省 政府网站建设网络营销第三版课本
  • 男女做爰高清免费视频网站网络营销网站建设案例
  • wordpress 模板丢失windows优化大师软件介绍
  • b2b网站建站网站建设工作总结
  • 义乌商城网站开发班级优化大师功能介绍
  • ps做网站边框推广资源seo