standards

Why size_t when int would suffice for the size of an array?

ⅰ亾dé卋堺 提交于 2019-12-01 14:07:03
问题 The C standard guarantees that an int is able to store every possible array size. At least, that's what I understand from reading §6.5.2.1, subsection 1 (Array subscripting constraints): One of the expressions shall have type ‘‘pointer to object type’’, the other expression shall have integer type, and the result has type ‘‘type’’. Since we shall use int s as array subscripts, why are we supposed to use size_t to determine the size of an array? Why does strlen() return size_t when int would

What is the behavior of writing a non-printing character in C/C++?

亡梦爱人 提交于 2019-12-01 12:47:12
Is the behavior of writing a non-printing character undefined or implementation-defined, if the character is written via printf / fprintf ? I am confused because the words in the C standard N1570/5.2.2 only talks about the display semantics for printing characters and alphabetic escape sequences. In addition, what if the character is written via std::ostream (C++ only)? The output of ASCII non-printable (control) characters is implementation defined. Specifically, interpretation is the responsibility of the output device. Edit 1: When the output device is opened as a file, it can be opened as

What is the preferred declaration convention for objects or arrays: const or let?

谁说我不能喝 提交于 2019-12-01 12:42:05
I'm not asking what's technically possible; I know you can do const a = []; const b = {}; a.push['sup']; b.test = 'earth'; What I'm wondering is whether there's any convention for preferring let over const when it comes to arrays and objects that will have their internals modified. If you see an object declared with const , do you assume the intention was for the object to be immutable, and would you have preferred to see let instead, or, since some linters (like tslint) have a problem with that, is it better just to declare it with const and trust that anyone else reading the code knows that

Is it legal C++ to pass the address of a static const int with no definition to a template?

我与影子孤独终老i 提交于 2019-12-01 11:09:20
I'm having trouble deciding whether not this code should compile or if just both compilers I tried have a bug (GCC 4.2 and Sun Studio 12). In general, if you have a static class member you declare in a header file you are required to define it in some source file. However, an exception is made in the standard for static const integrals. For example, this is allowed: #include <iostream> struct A { static const int x = 42; }; With no need to add a definition of x outside the class body somewhere. I'm trying to do the same thing, but I also take the address of x and pass it to a template. This

HTML Select and Text Input

馋奶兔 提交于 2019-12-01 10:43:53
We have all seen countless instances of forms with a select drop down having one of it's options as "Other" and on choosing that option, we get to see a input text box (which was hidden all along) asking us to type in our input. Is there a better way to implement this? Are there plugins out there which will let me do this better? Or are standard HTML elements suffice (some setting to a select tag, may be) ? An editable combobox might be a good alternative. The challenge is to style it in such a way that it is clear to the user that he can actually edit the contents of the control, rather than

HTML Select and Text Input

懵懂的女人 提交于 2019-12-01 09:29:15
问题 We have all seen countless instances of forms with a select drop down having one of it's options as "Other" and on choosing that option, we get to see a input text box (which was hidden all along) asking us to type in our input. Is there a better way to implement this? Are there plugins out there which will let me do this better? Or are standard HTML elements suffice (some setting to a select tag, may be) ? 回答1: An editable combobox might be a good alternative. The challenge is to style it in

Are there standard aliases for modules in Python?

久未见 提交于 2019-12-01 09:15:55
Following the guidelines proposed in this post , I am changing all the from module import function function(agt) by: import module as mdl mdl.function(agt) in my codes. I am trying to use commonly used aliases rather than personal ones. Is there a list of some kind on the internet summing-up all well-used aliases ? For instance, these appear to be pretty common: import numpy as np import math as m import matplotlib.pyplot as plt What about aliases for scipy.linalg , time , scipy.io , cmath and so on ? Which do you use ? Feel free to give other aliases, if no such list exist yet, I am willing

How to get wifi standard

[亡魂溺海] 提交于 2019-12-01 06:49:01
How can I get and change wifi standard, which I'm using now in my android device. For example: IEEE 802.11b or IEEE 802.11g or IEEE 802.11n. If this is possible. Its not possible to get what type of network the phone is connected to. However you can find the speed of the network: WifiManager wifiManager = Context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { Integer linkSpeed = wifiInfo.getLinkSpeed(); //measured using WifiInfo.LINK_SPEED_UNITS } P.S.: You can probably guess the type of network by interrogating the

Anonymous Methods / Lambda's (Coding Standards)

帅比萌擦擦* 提交于 2019-12-01 06:45:59
In Jeffrey Richter's "CLR via C#" (the .net 2.0 edtion page, 353) he says that as a self-discipline, he never makes anonymous functions longer than 3 lines of code in length. He cites mostly readability / understandability as his reasons. This suites me fine, because I already had a self-discipline of using no more than 5 lines for an anonymous method. But how does that "coding standard" advice stack against lambda's? At face value, I'd treat them the same - keeping a lambda equally as short. But how do others feel about this? In particular, when lambda's are being used where (arguably) they

What does “see below” mean when used as a type or exception specification?

淺唱寂寞╮ 提交于 2019-12-01 06:37:32
Looking through the C++ standard ( current draft http://isocpp.org/files/papers/N3690.pdf , sec 20.8.3 is one such place) and through LLVM's libc++ headers, I've found "see below" used as a type and exception specification. It seems to be used when no type exists, but it seemed strange to use a 2 word phrase for that instead of some sort of valid identifier. Is it discussed somewhere in the standard or elsewhere? Why/how is it used? see below is simply a place holder for one of a few possible types which are always described in the following text. For example here: typedef see below element