register int好像对常数优化并无作用

P3763 [TJOI2017] DNA

??? 改成int后在BZOJ上交一遍居然慢了20多ms
by Rye_Catcher @ 2018-04-22 15:57:18


怕玄学错误,不敢用不敢用
by 良月澪二 @ 2018-04-22 16:04:09


register别放在for循环里啊
by ikka @ 2018-04-22 16:05:42


register能很快的。。 比如这样写读入优化 P3371 用了register 96ms,不用 108ms ```cpp #include <cctype> #define rc register char #define ri register int char ss[1<<17],*A=ss,*B=ss; inline char gc() { return A==B&&(B=(A=ss)+fread(ss,1,1<<17,stdin),A==B)?EOF:*A++; } template<class T>inline void read(T& x) { char c;int y=1;while(c=gc(),!isdigit(c))if(c=='-')y=-1;x=c^48; while(c=gc(),isdigit(c))x=x*10+(c^48);x*=y; } char sr[1<<20],z[20];int C=-1,Z; template<class T>inline void wer(T x){ ri y=0;if(x<0)y=1,x=-x; while(z[++Z]=x%10+'0',x/=10);if(y)z[++Z]='-'; while(sr[++C]=z[Z],--Z);sr[++C]=' '; } ```
by ikka @ 2018-04-22 16:08:34


@[Rye_Catcher](/space/show?uid=61382) 对于c++11 无意义
by hiuseues @ 2018-04-22 18:52:11


@[hiuseues](/space/show?uid=95406) 直到现在,不只是无意义这么简单 c++11移除了一个名为`auto`的**储存类指定符**(当然auto这个词十分优美所以被作为C++11以后的类型推导声明器之一) `register`的确在C++11被弃用了,但在C++17,这个东西直接被干掉了。 >The register specifier is only allowed for objects declared at block scope and in function parameter lists. It indicates automatic storage duration, which is the default for these kinds of declarations. Additionally, the presence of this keyword may be used as a hint for the optimizer to store the value of this variable in a CPU register. This keyword was deprecated in C++11. (until C++17)
by constructor @ 2018-04-23 15:39:39


@[ikka](/space/show?uid=47055) 96ms和108ms甚至差几百ms在大部分OJ上说明不了什么。 写`register`确实没什么意义(不过觉着看着舒服写就写吧像`inline`一样)。 另外你想测谁快可以到[这](https://duck.ac/)。
by SovietPower✨ @ 2018-09-22 18:15:23


@[SovietPower✨](/space/show?uid=39887) 评测鸭卡的一批
by d3NtMDAw @ 2019-01-31 19:10:48


~~感觉对luogu评测鸡有用~~
by Guitar_Jasmine @ 2020-01-02 10:12:07


|