《Beginning C++17》-学习笔记-Chapter 10-Program Files and Preprocessing Directives

《Beginning C++17》-学习笔记-Chapter 01-Basic Ideas 书名:Beginning C++17 - From Novice to Professional 作者:Ivor Horton, Peter Van Weert 笔记: Blocks can be placed inside other blocks—this concept is called nesting. Blocks can be nested, one within anothe... 阅读详情
#include "..\Power.h"
/*including the file called Power.h located in the folder that includes the foler that includes this file.*/

Each source file, along with the contents of all the header files that you include in it, is called a translation unit.

The compiler processes each translation unit in a program independently to generate an object file.The object file contains machine code and information about references to entities such as functions that were not defined in the translation unit—external entities in other words.The set of object files for a complete program is processed by the linker, which establishes all necessary connections between the object files to produce the executable program module.

The combined process of compiling and linking translation units is referred to as translation.

In a given translation unit, no variable, function, class type, enumeration type, or template must ever be defined more than once.You can have more than one declaration for a variable or function, for example, but there must never be more than one definition that determines what it is and causes it to be created.

A declaration introduces a name into a scope.A definition not only introduces the name but also defines what it is.In other words, all definitions are declarations, but not all declarations are definitions.

The way that names in a translation unit are handled in the compile / link process is determined by a property that a name can have called linkage.Linkage expresses where in the program code the entity that is represented by a name can be.Every name that you use in a program either has linkage or doesn’t.A name has linkage when you can use it to access something in your program that is outside the scope in which the name is declared.If this isn’t the case, it has no linkage.If a name has linkage, then it can have internal linkage or external linkage.Therefore, every name in a translation unit has internal linkage, external linkage, or no linkage.

Internal linkage : The entity that the name represents can be accessed from anywhere within the same translation unit.For example, the names of non - inline variables defined at global scope that are specified as const have internal linkage by default.

External linkage : A name with external linkage can be accessed from another translation unit in addition to the one in which it is defined.In other words, the entity that the name represents can be shared and accessed throughout the entire program.All the functions that we have written so far have external linkage and so do both non - const and inline variables defined at global scope.

No linkage : When a name has no linkage, the entity it refers to can be accessed only from within the scope that applies to the name.All names that are defined within a block—local names, in other words—have no linkage.

In a program made up of several files, the linker establishes(or resolves) the connection between a function call in one source file and the function definition in another.When the compiler compiles a call to the function, it only needs the information contained in a function prototype to create the call.This prototype is contained within each declaration of the function.The compiler doesn’t mind whether the function’s definition occurs in the same file or elsewhere.This is because function names have external linkage by default.If a function is not defined within the translation unit in which it is called, the compiler flags the call as external and leaves it for the linker to sort out.

You can’t specify an initial value in an extern declaration because it’s a declaration of the name, not a definition of a variable.Declaring a variable as extern implies that it is defined in another translation unit.

/*A const variable, however, has internal linkage by default, which makes it unavailable in other translation units.You can override this by using the extern keyword in the definition :*/

extern const int power_range{ 3 }; // Definition of a global constant with external linkage

In the old days, the way to mark a name (function or variable name) for internal linkage was by adding the static keyword. The recommended way to define names with internal linkage today is through unnamed namespaces.
 

#define IDENTIFIER_FOR_A_SENTENCE "This is a sentence defined by an identifier."

#include <iostream>
#include <iomanip>

int main()
{
	std::cout << IDENTIFIER_FOR_A_SENTENCE << std::endl;
}
#define MAX(A, B) ((A) >= (B) ? (A) : (B))
#include <iostream>
#include <iomanip>

int main()
{
	std::cout << MAX(11, 22) << std::endl;//output 22
}
// Working with preprocessor operators
#include <iostream>
#define DEFINE_PRINT_FUNCTION(NAME, COUNT, VALUE) \
void NAME##COUNT() { std::cout << #VALUE << std::endl; }

DEFINE_PRINT_FUNCTION(fun, 123, Test 1 "2" 3)
/*With the definition, the line DEFINE_PRINT_FUNCTION(fun, 123, Test 1 "2" 3) became:
void fun123() { std::cout << "Test 1 \"2\" 3" << std::endl; }
*/

int main()
{
	fun123();
}

Standard Library names are declared within the std namespace.

#include <iostream>
#include <iomanip>

int main()
{
	std::cout << ::pow(2.0, 3) << std::endl;
	/*To explicitly access names defined in the global namespace, you use the scope resolution operator
without a left operand, for example, ::power(2.0, 3). This is only really required, though, if there is a more
local declaration with the same name that hides that global name.*/

}

All the Standard Library headers have preprocessing directives to prevent duplication.

All names declared inside an unnamed namespace have internal linkage(even names defined with an extern specifier).If a function is not supposed to be accessible from outside a particular translation unit, you should always define it in an unnamed namespace.Using a static specifier for this purpose is no longer recommended.
 

//  use the date and time macros to record when your program was last compiled.
#include <iostream>

int main()
{
	std::cout << "Program last compiled at " << __TIME__ << " on " << __DATE__ << std::endl;
}

// Demonstrating assertions
#include <iostream>

#include <cassert>
#define NDEBUG
int main()
{
	int y{ 5 };

	for (int x{}; x < 20; ++x)
	{
		std::cout << "x = " << x << " y = " << y << std::endl;
		assert(x < y);
		/*You should see an assertion message in the output when the value of x reaches 5. The program is
terminated by the assert() macro by calling std::abort() when x < y evaluates to false. The abort()
function is from the Standard Library, and its effect is to terminate the program immediately. As you can see
from the output, this happens when x reaches the value 5. The macro displays the output on the standard
error stream, cerr, which is always the command line. The message contains the condition that failed and
also the file name and line number in which the failure occurred.*/
	}
}

 

封神台靶场,为了小芳,冲之——cookie注入 第二个靶场 打开网站 找一下注入点 一般在新闻这种里面点开看看 先判断是否存在注入 有waf 尝试了很多方法绕过都没成功,/and/,aandnd,AnD等一系列都没绕过去,乌鸡鲅鱼 删掉id=169 发现 然后判断cookie注入 在搜索框输入 Javascript:alert(document.cookie=”id=”+escape(‘169’)); 然后弹窗了(其中 “id=” 取决URL中的id= escape中的数值也是URL中id=的值)返回刚刚的页面,把ID删除后一样能正常显示。说明服务器能 阅读详情

相关推荐

VisionPro 9.0 QuickBuild里用C#脚本调用Halcon 23.11模型,保姆级图文配置流程

本文详细介绍了如何在VisionPro 9.0 QuickBuild环境中使用C#脚本调用Halcon 23.11深度学习模型,提供从环境配置到模型集成的保姆级图文教程。重点解决图像格式转换、许可证配置等工业视觉检测中的常见问题,帮助开发者快速实现高效、稳定的视觉检测流水线部署。

weixin_27027459的博客 453

【C++】C++17的那些新特性

学习C++17的新特性。

慕雪华年的博客 8230

代码实现 —— 基于 STM32 的可见光通信系统课程设计

基于STM32F103ZET6,源码如需移植,需要修改定时器捕获通道引脚,及定时器,如果你也有这个课设任务,希望对你有所帮助。

不善挽留 1万+

【C++】别名

函数指针定义 方式 typedef using Examples 代码 #include &lt;iostream&gt; int Sum(int x, int y) { return x + y; } using FuncPtr_u = int (*)(int, int); // warning: alias declarations are a C++11 extensi...

weixin_43667627的博客 574

嵌入式开发避坑指南:手把手教你用STM32CubeMX配置W9825G6KH SDRAM(含时序参数详解)

本文详细介绍了如何使用STM32CubeMX配置W9825G6KH SDRAM,包括硬件连接检查、CubeMX初始化步骤、时序参数优化及稳定性问题排查。通过实测波形分析和案例分享,帮助开发者避免常见配置错误,提升嵌入式系统性能与稳定性。

weixin_42542669的博客 215

【牛股启动线】副图指标使用技术说明,图文案例分享,通达信炒股指标

如上图,在紫色线在黑色虚线上时,在出现紫色柱线时,通常会出现强势拉升的行情​。柱线加长加上紫色线上扬,进场跟随做多抓强势行情,紫色柱线和紫色线同时做多持续则可以继续持股。如上图,副图指标【牛股启动线】,指标信号包括紫色线走势信号和紫色柱线信号,以及底部的四条虚线技术信号​,还有一条绿色的参考线,一条黑色的虚线两天分档线。如上图,参考买点,紫色柱线开始出现时进场买点,在上图标记的位置对应的就是进场买点​。紫色柱线加长+紫色线上扬,多头共振持股,行情继续拉升阶段,持股待涨或顺势​进场做多。

weixin_69760830的博客 1934

66、unordered_map_hash

66、unordered_map_hash

m0_63008237的博客 265

​​​​手把手教你玩转RT-Thread操作系统专栏--​​​​第5章 设备驱动开发:RT-Thread的设备框架​​​​5.4 I2C/SPI驱动:如何驱动外部传感器(以MPU6050为例)​

通过本节学习,掌握了基于RT-Thread设备模型的I2C/SPI驱动开发流程,包括硬件初始化、寄存器读写、设备注册及应用程序调用。I2C(Inter-Integrated Circuit)和SPI(Serial Peripheral Interface)是嵌入式系统中最常用的两种串行总线协议,广泛用于连接传感器、存储器等外设。函数通过I2C协议读取外设寄存器的数据(如MPU6050的加速度寄存器)。SPI读取需先拉低片选(CS),发送寄存器地址,再读取数据,最后拉高CS。查找I2C设备,并调用。

xiaoheshang_123的博客 133

第一章C++对C的扩展(Externsion)--(6)引用

6.引用(Reference)6.1.引用的概念变量名,本身是一段内存的引用,即别名(alias)。此处引入的引用,是为己有变量起一个别名。 声明如下:int main() { int a; int &b = a; } 6.2.规则 1 引用没有定义,是一种关系型声明。声明它和原有某一变量(实体)的关系。故 而类型与原类型保持一致,且不分配内存。与被引用的变量有相同的地址。 2

613

关于cefsharp访问iqiyi.com显示403 Forbidden解决办法(2种方法)

cefsharp不加UserAgent的默认值为 (注意126是当前cefsharp的版本)Edge浏览器的UserAgent 为 (edge的版本是128的)说明根据浏览器的不同,UserAgent可能不太一样。

无线智能模块 可视DIY智能专家 1414

如何在 SAP BTP 上使用 Integration Suite 消费 S/4HANA Cloud API

SAP Integration Suite是一个集成平台即服务(iPaaS),允许开发人员顺利地将内部部署和基于云的应用程序和流程与SAP管理的工具和预构建内容进行集成。登录 SAP Business Technology Platform Cockpit,进入 integration suite:再点击 API management 进入 API Portal:或者直接从收藏夹里打开链接:https://304a49cetrial.integrationsuitetrial-apiportal.cfapp

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1708

C++17的inline variable

我们在C++的头文件中,定义一个变量,比如: int global_var = 10; 在多个.cc里面#inlucde这个头文件,编译会报”重复定义“的错误,而如果定义的是一个常量,比如: const int global_const = 10; 却不会报错,这是为什么呢? C++17的 ...

Enjoy Coding 3263

会计-合并-5- 增资、处置交易在合报与个报会计处理

摘要:本文系统梳理了股权投资会计处理的四种情形:从交易性金融资产转为权益法或成本法、权益法转成本法、权益法增持。核心原则是区分个报与合报处理,重点关注原投资公允/账面价值的计量差异及损益确认逻辑。对不丧失控制权的股权处置,个报确认投资收益,合报调整资本公积;丧失控制权时,个报需追溯调整权益法核算,合报计算综合投资收益。一揽子交易的特殊处理强调将过渡性差额暂记其他综合收益,最终丧失控制权时转入当期损益。文末通过典型案例演示了不同情境下的具体计算方法。

qq_34047402的博客 469

C++ 部分warning的解决办法

C++的warning可以不管理,但遇到极特殊的情况,可能会出bug,比如double转int。 本贴记录一些C++ warning的解决办法 Deprecated implicitely-declared copy constructor 如果定义了析构函数,那么会提示此warning,提供复制构造函数可解决此问题。 解决办法: class A{ public: A(){} A(cons...

LaineGates的专栏 1840

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

VScod:warning: deleted function definitions are a C++11 extension [-Wc++11-extensi

VScode使用c11语法输出的话,会打印警告。类似这种,看着比较闹心。 主要是CodeRunner插件默认的编译语句没有设置cpp标准为c11,修改即可。 第一步,找到插件栏,点击设置按钮。选择扩展设置 第二步:找到executor map点击进入settings.json 第三步:修改编译命令为g++ 为-std =c++11 注释之前的编译命令,使用如下命令,保存即可。 // "cpp": "cd $dir && g++ $fileName -o $...

= = 1952

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Mac 下的 VSCode c++11 extension warning

Mac 下的 VSCode c++11 extension warning 在mac下用Visual studio code写c++多线程时出现了这个警告: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]... 解决方案: 打开terminal: 如果使用的是bash: echo "alias g+...

qq_45181615的博客 6232

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

VS Code 解决 Clang 编译时的警告 [-Wc++11-extensions]

今天在使用 VS Code 的时候刷 PAT 的时候,有写到这样的一行语句: for (char c : s1) { 编译时遇到了一条警告: Warning: [-Wc++11-extensions] 大意已经很明确了,基于范围的 for 语句是 C++11 标准的内容。那么,如何在编译中指定所用标准呢? 在设置中找到 code-runner: executor map,选择在 settings.json 中编辑 找到 C++ 这一行 "cpp": "cd $dir && g++

覆鹿寻蕉的博客 4979

处理iOS开发中的各种警告

iOS开发中我们会遇到各种警告,包括第三方不再支持更新导致的警告,苹果一些过时方法的警告,其中尤其是ASIHttpRequest的不支持更新导致有很多的警告,所以我在这里做了罗列 Semantic Warnings WarningMessage -WCFString-literal input conversion stopped due to an inpu...

3165

C++17新特性个人总结

目录 C++17 1 关键字 1.1 constexpr 1.2 static_assert 1.3 auto 1.4 typename 1.5 inline 2 语法 2.1 折叠表达式 2.2 结构化绑定 2.3 允许非类型模板参数进行常量计算 2.4 条件分支语句初始化 2.5 聚合初始化 2.6 嵌套命名空间 2.7 lambda表达式捕获*this的值...

我的博客 3万+

解决在vsode中使用C++17遇到的问题

解决在vsode中使用C++17遇到的问题 通过 gcc -v 检查 gcc 的版本,要想 vscode 完全使用 C++17 的功能,gcc 的版本至少 gcc7 才行。然而,gcc11 以上的版本才会默认开启 C++17,所以我们需要配置编译器,让编译器用C++17的语法规则编译我们的代码。 vscod本身不是编译器,需要添加配置文件才具备编译 C++ 代码的功能。具体怎么添加配置和设置文件,网上有很多,这里不做介绍。找到配置文件 tasks.json , 在 “args” 参数选项里面添加 -std=

qq_33899456的博客 6110

warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions

NDK 开发中出现下面的错误. 说是 在类初始化非静态数据成员是C++ 11扩展 意思是 必须让编译器是c++11 的扩展 xyyyplayer/src/main/cpp/XYCallJava.h:16:20: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-exte...

六道对穿肠的学习之旅 5679

C语言文档中的no linkage理解

no linkage:对于在两个不同地方声明的同名标识符,他们不是指向同一实体,而是指向各自的实体。 那么哪些标识符是no linkage的呢? 除了变量和函数之外的其他任何标识符和处于块作用域内的同名变量但是没有使用extern修饰的变量。 这些标识符都始终指向独自唯一的那个实体。 ...

lengye7的博客 4203

gcc编译部分编译选项

我只写出一些我没有在文档中查到的,网上也搜索不出来什么明确的资料。正确性实在不敢保证。 https://gcc.gnu.org/onlinedocs/gcc-7.3.0/gcc/Option-Summary.html#Option-Summary 这是文档。 使用gcc命令显示的帮助信息 用法:gcc [选项] 文件... 选项: -pass-exit-codes

JabamiYu的博客 3万+

Linkage Types

Objects, references, functions, types, templates, and namespaces are all considered names. A name can have one of three linkage types: external linkage, internal linkage, or no linkage. The linkag

majcos的专栏 1222

《C++ Without Fear》学习笔记

书名:C++ Without Fear A Beginner’s Guide That Makes You Feel Smart 作者:Brian Overland 阅读时间:2018/10/6-2018/10/20 书摘+书评: An important rule of good programming style is that variables should usually...

CodingIsFun 832
上一篇: 《Beginning C++17》-学习笔记-Chapter 09-Functions Templates
下一篇: 《Beginning C++17》-学习笔记-Chapter 11-Defining Your Own Data Types
CodingIsFun
博客等级 码龄8年 37粉丝 240原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址