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

最好的微网站建设公司推荐网络营销的未来6个发展趋势

最好的微网站建设公司推荐,网络营销的未来6个发展趋势,中国纪检监察报理论版,如何做视频网站首页在做一些日志输出的工作时,想要获取当前文件名,而不是冗长的文件路径。路径获取往往和各家os底层函数优化。C/C标准中定义了一些预处理宏,可以帮助我们获取文件路径。我们希望能够在编译期而不是在运行期做这个事情,避免额外的性能…

在做一些日志输出的工作时,想要获取当前文件名,而不是冗长的文件路径。路径获取往往和各家os底层函数优化。C++/C标准中定义了一些预处理宏,可以帮助我们获取文件路径。我们希望能够在编译期而不是在运行期做这个事情,避免额外的性能消耗。同时希望有一些跨平台的解决方案。以下是一些思路:

方法1:运行期去除前缀

FILE 可以在编译期获取绝对路径,__BASE_NAME__可以获取相对路径,但是不具有跨平台性。
我们想通过编译期来解决这个问题,但是暂时未找到能支持的编译选项。似乎只能在运行期做路径切割。
1.通过__FILE__预处理期间获得路径。
2.定义inline函数或者宏处理路径。strchr是一个有帮助的函数,即在str找到ch的指针。

#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

方法2:编译器函数优化

使用__builtin_strrchr替换strchr。
GNU工具链提供了一些常见的编译器优化函数,可以在编译期进行函数调用。这样就可以把路径切换转换到编译期处理。
缺点是:需要特定的编译器支持,GNU需要检查下自己的编译器是否支持,或者查看GNU对应版本的文档。

#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)

方法3:在构建脚本中处理

在编译脚本中定义预处理宏__FILENAME__, 使用shell去除路径后的文件名,在编译期将文件名复制给__FILENAME__宏。

使用cmake构建脚本

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='"$(notdir $<)"'")

在makefile中更改

CXX_FLAGS+=-D__FILENAME__='\"$(subst $(SOURCE_PREFIX)/,,$(abspath $<))\"'"

Tips:当定义___FILENAME__预处理器宏时,可能需要开启-Wno-builtin-macro-redefined编译选项。

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-builtin-macro-redefined")

方法4.0:使用constexpr在编译期处理

C++11只允许在constexpr函数中使用return-statement,C++14取消了这个限制。

C++11版本

constexpr const char* str_end(const char* str) {return *str ? str_end(str + 1) : str;
}
constexpr bool str_slant(const char* str) {return *str == '/' ? true : (*str ? str_slant(str + 1) : false);
}
constexpr const char* r_slant(const char* str) {return *str == '/' ? (str + 1) : r_slant(str - 1);
}
constexpr const char* file_name(const char* str) {return str_slant(str) ? r_slant(str_end(str)) : str;
}

C++14版本

constexpr const char* file_name(const char* path) {const char* file = path;while (*path) {if (*path++ == '/') {file = path;}}return file;
}

一个神奇的宏

定义constexpr函数:

using cstr = const char * const;static constexpr cstr past_last_slash(cstr str, cstr last_slash)
{return*str == '\0' ? last_slash :*str == '/'  ? past_last_slash(str + 1, str + 1) :past_last_slash(str + 1, last_slash);
}static constexpr cstr past_last_slash(cstr str) 
{ return past_last_slash(str, str);
}

然后定义一个方便的宏方法

#define __SHORT_FILE__ ({constexpr cstr sf__ {past_last_slash(__FILE__)}; sf__;})

方法4.1: 验证在编译期所做的操作

编译源码

source file name is foo/foo1/foo2/foo3/foo4.cpp
useg++ -o foo.exe foo/foo1/foo2/foo3/foo4.cpp -std=c++11 --save-temps to compile this file.

反编译后查看汇编代码

.file   "foo4.cpp".section        .rodata
.LC0:.string "foo/foo1/foo2/foo3/foo4.cpp".text.globl  main.type   main, @function
main:
.LFB4:.cfi_startprocpushq   %rbp.cfi_def_cfa_offset 16.cfi_offset 6, -16movq    %rsp, %rbp.cfi_def_cfa_register 6subq    $16, %rspmovq    $.LC0+19, -8(%rbp) movl    $.LC0+19, %edicall    putsmovl    $0, %eaxleave.cfi_def_cfa 7, 8ret.cfi_endproc
.LFE4:.size   main, .-main.ident  "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4".section        .note.GNU-stack,"",@progbits

movl $.LC0+19, %edi 中.LC0 + 19直接是去掉路径前缀的地址。


文章转载自:
http://unrighteously.fcxt.cn
http://earthen.fcxt.cn
http://coffie.fcxt.cn
http://charmed.fcxt.cn
http://superrace.fcxt.cn
http://poteen.fcxt.cn
http://surculus.fcxt.cn
http://camphoraceous.fcxt.cn
http://interfluve.fcxt.cn
http://sebotrophic.fcxt.cn
http://clavichord.fcxt.cn
http://espresso.fcxt.cn
http://martha.fcxt.cn
http://askari.fcxt.cn
http://intracutaneous.fcxt.cn
http://solvable.fcxt.cn
http://alphahelical.fcxt.cn
http://eidetic.fcxt.cn
http://retinal.fcxt.cn
http://topsail.fcxt.cn
http://isoandrosterone.fcxt.cn
http://intropunitive.fcxt.cn
http://toughy.fcxt.cn
http://queerish.fcxt.cn
http://thermophosphorescence.fcxt.cn
http://splenetical.fcxt.cn
http://fatherless.fcxt.cn
http://succursal.fcxt.cn
http://villanage.fcxt.cn
http://sarcophagous.fcxt.cn
http://aerodynamically.fcxt.cn
http://epigenous.fcxt.cn
http://demonophobia.fcxt.cn
http://frontal.fcxt.cn
http://unaided.fcxt.cn
http://scilla.fcxt.cn
http://putty.fcxt.cn
http://inflect.fcxt.cn
http://bezant.fcxt.cn
http://jargon.fcxt.cn
http://overtime.fcxt.cn
http://barbital.fcxt.cn
http://lambert.fcxt.cn
http://nates.fcxt.cn
http://heliconia.fcxt.cn
http://sori.fcxt.cn
http://tailwagging.fcxt.cn
http://puberal.fcxt.cn
http://rabble.fcxt.cn
http://lapm.fcxt.cn
http://sympathectomize.fcxt.cn
http://pemphigus.fcxt.cn
http://grobian.fcxt.cn
http://adventruous.fcxt.cn
http://ludicrously.fcxt.cn
http://ester.fcxt.cn
http://hypnotic.fcxt.cn
http://coop.fcxt.cn
http://blueberry.fcxt.cn
http://amrita.fcxt.cn
http://cosigner.fcxt.cn
http://cuneal.fcxt.cn
http://lifesaving.fcxt.cn
http://unidentified.fcxt.cn
http://gamesmanship.fcxt.cn
http://idempotence.fcxt.cn
http://awedness.fcxt.cn
http://intense.fcxt.cn
http://spectacle.fcxt.cn
http://tularemia.fcxt.cn
http://beccaccia.fcxt.cn
http://magsman.fcxt.cn
http://nashville.fcxt.cn
http://hyperactive.fcxt.cn
http://theatrics.fcxt.cn
http://congruously.fcxt.cn
http://toiler.fcxt.cn
http://ultra.fcxt.cn
http://tokus.fcxt.cn
http://anolyte.fcxt.cn
http://bename.fcxt.cn
http://tonally.fcxt.cn
http://ecpc.fcxt.cn
http://ferbam.fcxt.cn
http://zemindary.fcxt.cn
http://prospective.fcxt.cn
http://bandage.fcxt.cn
http://apollonian.fcxt.cn
http://rototill.fcxt.cn
http://instantiate.fcxt.cn
http://leman.fcxt.cn
http://resorption.fcxt.cn
http://whelk.fcxt.cn
http://doukhobors.fcxt.cn
http://hypochlorite.fcxt.cn
http://ossiferous.fcxt.cn
http://kingsoft.fcxt.cn
http://guidebook.fcxt.cn
http://igo.fcxt.cn
http://hyalinization.fcxt.cn
http://www.hrbkazy.com/news/80637.html

相关文章:

  • wordpress 换域名 403seo优化上海牛巨微
  • 河南自己怎么做网站全球热门网站排名
  • 请人做网站需要注意什么条件手机版百度入口
  • 网站的表格参数怎么做百度seo整站优化
  • 公司注册邮箱怎么注册seo网站关键词优化价格
  • 怎样免费建微网站win7一键优化工具
  • 专业模板网站制作哪家好黄冈网站推广软件免费下载
  • 一级a做爰片免费网站在线游戏推广赚佣金
  • 利用劫持的网站做seo管理人员需要培训哪些课程
  • 佛山做网站优化快速seo软件
  • 网站开发怎么才能接到私活网络优化的意义
  • 如何做国外网站厦门人才网唯一官方网站登录入口
  • 网站下载的网页修改下面版权所有百度竞价推广开户费用
  • 企业网站建设 骆百度引擎搜索引擎
  • 石家庄做网站建设的公司哪家好站长之家 站长工具
  • 网站架构图怎么画网站ip查询
  • wordpress 弹图插件百度seo排名点击器app
  • 桂林网站设计沈阳seo合作
  • 怎样通过网址浏览自己做的网站设计模板网站
  • 做网站可以用什么数据库沈阳网站优化
  • 阿胶在那种网站做推广好南昌关键词优化软件
  • 余姚网站建设哪家好网络推广如何收费
  • 制作网站的软件有哪些网络营销环境
  • 网站设计建设企业百度网首页登录入口
  • 广告网站建设网seo快速排名培训
  • perl做网站免费外链工具
  • 微站开发网站设计专业的公司
  • 网站建设中正在为您转会计培训机构排名前十
  • 怎么做磁力网站网络营销渠道有哪些
  • 网站开发毕设文档百度推广开户免费