C++ - 表达式求值顺序

一文搞懂C++常见运算符优先级 文章介绍了初学C++的同学在算术表达式中容易混淆的部分,通过两个例子演示了代码的运算顺序和结果,并总结了C++中常见运算符的优先级顺序。总之,这篇文章可以帮助初学者更好地理解C++中的运算符优先级 阅读详情

在C++里,表达式求值顺序一直是一个大坑,这是由于为了给编译器更大的优化空间,C++对表达式的求值做了许多非常灵活的规定(其实就是不规定,编译器愿意怎么实现都可以)。这些灵活的规定也给C++带来了许多在其它语言中不存在的未定义行为(undefined behavior),比如i=i++,甚至有一些是标准委员会都没有预想到。

在C++03里,表达式的求值顺序依靠序列点(sequency point)来定义。有关序列点的介绍,在 这里 和 这里 可以见到。但是其中也提到了序列点所存在的一些问题。到了C++11,标准委员会放弃了序列点,而使用了一种新的方式定义表达的求值顺序。两种定义的结果大同小异,这里使用C++11的定义方式,介绍一下C++中的表达式求值。

C++11中还引入线程的概念,不过这里讨论的是同一线程中表达式的求值顺序,不讨论不同线程之间的顺序与同步的问题。

一些定义

side effect 副作用

访问(读或写)volatile的变量,修改一个对象(变量),调用系统I/O函数,或调用会发生以上三种行为函数,统称为副作用。对表达式的求值,不只包括求出表达式值(即返回值,value computation),还包括完成表达式中的包含的各种副作为。

如

int i=1;
i++; // 对其求值包括两部分,计算返回值(1),以及其副作用(将i赋值为2)

full-expression 完整表达式

一个完整式指不是其它表达式子表达式的表达式。

关于C/C++ 表达式求值顺序   表达式求值顺序不同于运算结合性和优先级。下面是一个经典例子,被 ISO C99/ C++98 /03 三大标准明确提到:他的结果是不确定(unspecified) 的。 i = ++i + 1;   // The behavior is unspecified     在介绍概念之前,我们先解释一下它的结果。这个表达式( expression )包含3个子表达式( subexp 阅读详情

相关推荐

IIS - 会话cookie中缺少HttpOnly属性

不啰嗦,我们直接开始! 先进行常规设置 打开配置编辑器 选中图中节点,将httpOnlyCookies设置为true 然后。。。不起作用。。。 换种方式 通过配置出站规则getcookie添加HttpOnly 在Web.config中添加如下出站规则 <rewrite> <outboundRules> <rule name="Add HttpOnly"> <match serverVa.

。 21万+

从NVLINK到EthLink:GPU互联技术演进全解析(含最新行业趋势)

本文深入解析了从NVLINK到EthLink的GPU互联技术演进,重点剖析了Scale-up与Scale-out两种核心范式。文章详细对比了NVLINK、UALINK及革命性的EthLink技术,后者创新性地将以太网改造为支持Load/Store与RDMA双语义的高性能互联网络,旨在打破封闭生态,实现高性能与开放性的统一。最后,文章提供了技术选型指南并展望了未来以以太网为主导、语义融合的行业趋势。

weixin_29204749的博客 198

YOLOv8 轴承缺陷检测 使用YOLOv8进行训练、评估和可视化预测结果 包含1440张图片的轴承缺陷检测数据集 YOLO格式或XML格式

本文介绍了一个基于YOLOv8的轴承缺陷检测项目。数据集包含1440张图片,标注了4类缺陷(凹槽、凹陷、卡伤、划痕),按8:1:1比例划分为训练集(1152张)、验证集(144张)和测试集(144张)。标注文件支持YOLO格式和XML格式,可直接用于模型训练。项目实现了数据准备、模型训练、评估及可视化预测结果的全流程,使用YOLOv8n预训练模型进行50个epoch的训练,并提供了数据格式转换(XML转YOLO)的代码示例。最终模型可自动检测轴承表面缺陷,并保存预测结果。

OICQQ67658008的博客 1466

SAP 批量处理分包事后调整:BAPI_GOODSMVT_CREATE 关键参数与避坑指南

本文详细解析了SAP系统中使用BAPI_GOODSMVT_CREATE进行分包事后批量调整的关键参数配置与常见错误排查。重点介绍了GOODSMVT_CODE设置为'07'的必要性、GOODSMVT_ITEM结构体的正确配置方法,以及如何避免M7384、M7386等常见错误,帮助用户高效处理分包业务中的数量调整问题。

weixin_29276847的博客 575

eLabRadio软件无线电虚实结合仿真开发平台简介

在使用仿真平台时,不要关闭设备或断开设备与PC机之间的网络连接,否则,仿真平台将无法正常工作。注:采用eNodeX设备认证方式,当出现“设备不存在”的报错时,请检查计算机IP是否和硬件设备IP处于同一网段,或者是否是先连接好网线,再开启硬件设备的。①此登录方式下,需要先建立软件与硬件的通信:在登录窗口点击【网络配置】,参照下图输入设备IP,服务器地址无需设置,设置完成后点击确认,此时登录界面无需设置账号密码;,拷贝到电脑上,使用管理员权限运行setup.exe,下一步直到安装完成,桌面会生成快捷方式。

weixin_55349105的博客 6356

海思图像质量之HiPQTool调试

文章目录一. HiPQTool 界面二. 图像调试三. 将调试参数写入程序中 一. HiPQTool 界面 二. 图像调试 三. 将调试参数写入程序中

lzg2011的博客 2389

人形机器人维护保养指南:硬件工程师必备手册

随着科技的不断进步,人形机器人在各个领域的应用越来越广泛。本指南的目的是为硬件工程师提供一份系统、全面的人形机器人维护保养手册,涵盖从基础概念到实际操作的各个方面,帮助工程师们更好地理解和处理人形机器人在使用过程中出现的各种问题,确保机器人的正常运行。本文将首先介绍人形机器人维护保养涉及的核心概念,解释各硬件组件的原理和它们之间的关系;接着阐述维护保养的核心算法原理和具体操作步骤,结合数学模型进行详细讲解;然后通过项目实战案例展示如何在实际中应用这些知识;

AI天才研究院 975

19、CATIA V5:参数化建模与零件目录创建全解析

本文详细解析了在CATIA V5中通过设计表实现参数化建模及零件目录创建的完整流程。以支撑块和钩形夹为例,介绍了参数识别、设计表创建与关联、配置管理以及零件目录的构建方法。同时,提供了实际操作建议和注意事项,帮助设计师高效创建和管理零件族,提升设计效率和质量。

raspberrypi5的博客 454

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

上一篇: C++ -- 数组 vs 指针
下一篇: c++ – 标准容器可以继承吗
fefe82
博客等级 码龄12年 417粉丝 6原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值