standards

Is reading into uninitialized memory space ALWAYS ill advised?

馋奶兔 提交于 2020-01-17 14:03:10
问题 I am recreating the entire standard C library and I'm working on an implementation for strle n that I would like to be the basis of all my other str functions. My current implementation is as follows: int ft_strlen(char const *str) { int length; length = 0; while(str[length] != '\0' || str[length + 1] == '\0') length++; return length; } My question is that when I pass a str like: char str[6] = "hi!"; As expected, the memory reads: ['h']['i']['!']['\0']['\0']['\0']['\0'] If you look at my

C++ Converting unsigned to signed integer portability

£可爱£侵袭症+ 提交于 2020-01-17 01:21:27
问题 I know that in C the conversion of unsigned to signed integers is implementation defined, but what is it for C++? I figured someone would have asked this already, and I searched but I couldn't find it. I have a function that operates on an unsigned integer and returns a related unsigned integer. I am passing that function a signed integer by casting to unsigned similar to int num = -6; unsigned ret = func((unsigned)num); int ret_as_signed = (int)ret; . In Visual Studio that works fine, but I

What if an argument has the same name as that of a data member?

偶尔善良 提交于 2020-01-16 09:59:38
问题 #include <iostream> struct A { A(int n) { std::cout << n; } int n{2}; }; int main() { A a{1}; } The output is 1 rather than 2 . Does the C++ standard define that the argument name is preferred if it is the same as that of a data member? 回答1: The argument is in a "closer" scope than the member variable, so the argument shadows the member variable. The obvious solution is to rename the argument (or the member variable), so they are not the same anymore. You can also use this->n to explicitly

Checking all conditions in a logical disjunction

 ̄綄美尐妖づ 提交于 2020-01-16 01:10:37
问题 I found the question in this line of code. Ignore the fact that this code does not make sense: if (object != null || object.someMethod()) object.doSomething(); First I was thinking that this code will throw NullPointerException if object is null. But, this is a logical disjunction and if one of the conditions is true the whole condition is true. So the compiler doesn't checks the second condition and doesn't throws NullPointerException . Is this Java Standard behavior or implementation

How do I byte-swap a signed number in C?

自古美人都是妖i 提交于 2020-01-14 16:35:36
问题 I understand that casting from an unsigned type to a signed type of equal rank produces an implementation-defined value: C99 6.3.1.3: Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised. This means I don't know how to byte-swap a signed number. For instance, suppose I am receiving two-byte, twos-complement signed values in little-endian order from a peripheral device, and

How do I byte-swap a signed number in C?

你。 提交于 2020-01-14 16:32:31
问题 I understand that casting from an unsigned type to a signed type of equal rank produces an implementation-defined value: C99 6.3.1.3: Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised. This means I don't know how to byte-swap a signed number. For instance, suppose I am receiving two-byte, twos-complement signed values in little-endian order from a peripheral device, and

How do I byte-swap a signed number in C?

久未见 提交于 2020-01-14 16:32:06
问题 I understand that casting from an unsigned type to a signed type of equal rank produces an implementation-defined value: C99 6.3.1.3: Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised. This means I don't know how to byte-swap a signed number. For instance, suppose I am receiving two-byte, twos-complement signed values in little-endian order from a peripheral device, and

What are the actual formats supported by CngKeyBlobFormat?

坚强是说给别人听的谎言 提交于 2020-01-14 08:30:36
问题 The Microsoft pages provide "minimal" information about the formats that can be used by CngKey.Import. Which actual formats are actually represented by the following CngKeyBlobFormat properties? EccPrivateBlob EccPublicBlob GenericPrivateBlob GenericPublicBlob OpaqueTransportBlob Pkcs8PrivateBlob Only the PKCS#8 private key format hints slightly about the format of the key, but it doesn't specify if the private key needs to be wrapped or if just the inner PKCS#8 structure is accepted. The

Does anyone change the Visual Studio default bracing style? - Is there a standard?

蓝咒 提交于 2020-01-14 06:56:33
问题 I find the default bracing style a bit wasteful on line count eg... function foo() { if (...) { ... } else { ... } } would, if I was writing in JavaScript for example be written like... function foo() { if (...) { ... } else { ... } } ...which I understand may also not be to peoples' tastes. But the question(s) is/are do you turn off the VS formatting style and use your own rules? What is the opinion of this in the industry when many people are working on the same code-base? Is it better just

What are the key decisions to get right when designing a fully Unicode-aware language or library?

孤街醉人 提交于 2020-01-14 03:19:09
问题 Looking at Tom Christiansen's talk 🔫 Unicode Support Shootout 👍 The Good, the Bad, & the (mostly) Ugly 👎 working with text seems to be so incredibly hard, that there is no programming language (except Perl 6) which gets it even remotely correct. What are the key design decisions to make to have a chance to implement Unicode support correctly on a clean table (i. e. no backward-compatibility requirements). What about default file encodings, which transfer format and normalization format to use