auto

C语言中auto,register,static,const,volatile的区别

大憨熊 提交于 2019-12-05 21:23:35
1)auto   这个关键字用于声明变量的生存期为自动,即将不在任何类、结构、枚举、联合和函数中定义的变量视为全局变量,而在函数中定义的变量视为局部变量。这个关键字不怎么多写,因为所有的变量默认就是auto的。 (2)register   这个关键字命令编译器尽可能的将变量存在CPU内部寄存器中而不是通过内存寻址访问以提高效率。 (3)static   常见的两种用途:     1>统计函数被调用的次数;     2>减少局部数组建立和赋值的开销.变量的建立和赋值是需要一定的处理器开销的,特别是数组等含有较多元素的存储类型。在一些含有较多的变量并且被经常调用的函数中,可以将一些数组声明为static类型,以减少建立或者初始化这些变量的开销.   详细说明:     1>、变量会被放在程序的全局存储区中,这样可以在下一次调用的时候还可以保持原来的赋值。这一点是它与栈变量和堆变量的区别。     2>、变量用static告知编译器,自己仅仅在变量的作用范围内可见。这一点是它与全局变量的区别。     3>当static用来修饰全局变量时,它就改变了全局变量的作用域,使其不能被别的程序extern,限制在了当前文件里,但是没有改变其存放位置,还是在全局静态储存区。   使用注意:     1>若全局变量仅在单个C文件中访问,则可以将这个变量修改为静态全局变量,以降低模块间的耦合度;   

Different behavior observed with constexpr auto/char-array variable

≡放荡痞女 提交于 2019-12-05 18:43:51
Following up with this question Having a constexpr static string gives a linker error In the question, this code wasn't able to compile: #include <iostream> struct Test { static constexpr char text[] = "Text"; }; int main() { std::cout << Test::text << std::endl; // error: undefined reference to `Test::text' } From the comment, this code is able to compile: #include <iostream> struct Test { static constexpr auto text = "Text"; }; int main() { std::cout << Test::text << std::endl; } My question is why the auto version works but the array of char version doesn't? Could you please point out the

Why would they special-case certain initializer lists instead of treating them all the same?

旧城冷巷雨未停 提交于 2019-12-05 18:31:27
Say I have a variable auto x that I want to initialize to 7 using brace initialization, simple: auto x {7}; Except I learned that x is NOT an integer, but an initialization list itself. Why? Is there a specific reason why the committee would decide that auto should grab the initialization list in the case of a single auto value, or do they expect us to just realize these shouldn't be used together. I cant seem to think of a possible reason i would want an initializer list to be stored into auto as opposed to the value A very practical answer is, "why should int be selected?" Or double , or any

auto&& variable's are not rvalue reference

浪子不回头ぞ 提交于 2019-12-05 18:22:31
Why auto&& is not rvalue reference? Widget&& var1 = Widget(); // rvalue reference auto&& var2 = var1; //var2 not rvalue reference below are rvalue reference example void f(Widget&& param); // rvalue reference Widget&& var1 = Widget(); // rvalue reference Why var2 is not rvalue reference but f and var2 are rvalue references? Once the type of the initializer has been determined, the compiler determines the type that will replace the keyword auto using the rules for template argument deduction from a function call (see template argument deduction#Other contexts for details). The keyword auto may

日常 - 在 Windows 系统下使用批处理文件自动提交代码到 GitHub 上

不想你离开。 提交于 2019-12-05 16:43:48
需求 每天都上传代码到 GitHub 上,需要一种脚本文件自动完成一些重复的工作。 git add . git commit -m "message" git push 缺点是上传的 message 都为 "auto commit",违背了代码管理的初衷,以后查看这些 message 很难知道当时修改了什么内容。 经过测试可得,如果当天没有修改项目文件内容,则不会完成 add commit push 操作。因此也可以在需要记录的当天手动执行 commit,加上一些必要的 message 信息,批处理文件则会完成 push 操作。 此前准备,需要已经配置好手动完成 push 到远程仓库的操作,在这种条件下才能完成自动化脚本的正确运行。 实现 编写文件 先在 Windows 下创建一个 leetcode.txt 文件,并输入以下内容。完成后更改文件内容后缀名,使其变成 leetcode.bat 批处理文件。 @echo off @title bat execute git auto commit F: cd F:/Code/Java/algorithm/leetcode git add . git commit -m "Auto commit." git push 解释说明:再次强调,如果看了这些解释仍不清楚 bat 文件的作用则需要先手动 commit 到 GitHub 上。

auto.js用于手机app的js脚本

青春壹個敷衍的年華 提交于 2019-12-05 15:44:01
在搜索如何自动添加qq好友的时候看见了有人用auto.js的方法 https://www.bilibili.com/video/av28079383/?spm_id_from=333.788.videocard.5 搜索了autojs没想到还挺正式的有文档,在github上 https://hyb1996.github.io/AutoJs-Docs/#/ b站上有人做了教程 https://www.bilibili.com/video/av67357100 来源: https://www.cnblogs.com/lionli/p/11932846.html

CSS兼容性技巧整理--从IE6-IE9 火狐谷歌浏览器兼容

陌路散爱 提交于 2019-12-05 14:00:04
CSS兼容性技巧整理--从IE6-IE9 火狐谷歌浏览器兼容 本文收集整理了IE7,6与Fireofx的CSS兼容性处理技巧,供大家参考。   CSS兼容常用技巧   请尽量用xhtml格式写代码,而且DOCTYPE影响 CSS 处理,作为W3C标准,一定要加DOCTYPE声明。    1.div的垂直居中问题   vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字,就垂直居中了。缺点是要控制内容不要换行    2. margin加倍的问题   设置为float的div在ie下设置的margin会加倍。这是一个ie6都存在的bug。解决方案是在这个div里面加上display:inline;   例如:   <#div id=”imfloat”>   相应的css为   #imfloat{   float:left;   margin:5px;   display:inline;}    3.浮动ie产生的双倍距离   #box{ float:left; width:100px; margin:0 0 0 100px; //这种情况之下IE会产生200px的距离 display:inline; //使浮动忽略}   这里细说一下block与inline两个元素:block元素的特点是,总是在新行上开始

CSS兼容性技巧整理--从IE6-IE9 火狐谷歌浏览器兼容

别来无恙 提交于 2019-12-05 13:59:43
CSS兼容性技巧整理--从IE6-IE9 火狐谷歌浏览器兼容 本文收集整理了IE7,6与Fireofx的CSS兼容性处理技巧,供大家参考。   CSS兼容常用技巧   请尽量用xhtml格式写代码,而且DOCTYPE影响 CSS 处理,作为W3C标准,一定要加DOCTYPE声明。    1.div的垂直居中问题   vertical-align:middle; 将行距增加到和整个DIV一样高 line-height:200px; 然后插入文字,就垂直居中了。缺点是要控制内容不要换行    2. margin加倍的问题   设置为float的div在ie下设置的margin会加倍。这是一个ie6都存在的bug。解决方案是在这个div里面加上display:inline;   例如:   <#div id=”imfloat”>   相应的css为   #imfloat{   float:left;   margin:5px;   display:inline;}    3.浮动ie产生的双倍距离   #box{ float:left; width:100px; margin:0 0 0 100px; //这种情况之下IE会产生200px的距离 display:inline; //使浮动忽略}   这里细说一下block与inline两个元素:block元素的特点是,总是在新行上开始

What is difference between decltype(auto) and decltype(returning expr) as return type?

£可爱£侵袭症+ 提交于 2019-12-05 13:39:09
问题 What is the difference between decltype(auto) and decltype(returning expression) as return type of a function (template) if expr used without parentheses in both cases? auto f() -> decltype(auto) { return expr; } // 1 auto f() -> decltype(expr) { return expr; } // 2 Above f can be defined/declared in any context and can be either (member) function or (member) function template, or even (generic) lambda. expr can depend on any template parameters. In second version both expr are exactly the

Error with using decltype() in C++11 (creating opaque error message in gcc 4.7.0)

穿精又带淫゛_ 提交于 2019-12-05 12:19:44
问题 with the following code (a boiled-down version of my original code) #include <iostream> #include <cmath> template <typename> class A; // edit 1 following Mark & Matthieu template <typename X> class A { X a; template <typename> friend class A; // edit 1 following Mark & Matthieu public: A(X x) : a(x) {} X get() const { return a; } // edit 2 to avoid using A<Y>::a template <typename Y> auto diff(A<Y> const& y) const -> decltype(a - y.a) // original code causing error with gcc -> typename std: