standards

Conversion between signed integer and unsigned integer

扶醉桌前 提交于 2019-12-10 23:35:40
问题 If I cast an unsigned integer to a signed integer then cast back, am I guaranteed to get the original value? For example, does this function always return true for any x on any platform according to the C++ standard? bool f(unsigned int x) { return x == static_cast<unsigned int>(static_cast<int>(x)); } What about this one? bool g(int x) { return x == static_cast<int>(static_cast<unsigned int>(x)); } 回答1: The answer is "no, this is not guaranteed" for both f and g . Here is what the standard

What's the standard-defined endianness of std::wstring?

霸气de小男生 提交于 2019-12-10 20:46:58
问题 I know the UTF-16 has two types of endiannesses: big endian and little endian. Does the C++ standard define the endianness of std::wstring? or it is implementation-defined? If it is standard-defined, which page of the C++ standard provide the rules on this issue? If it is implementation-defined, how to determine it? e.g. under VC++. Does the compiler guarantee the endianness of std::wstring is strictly dependent on the processor? I have to know this; because I want to send the UTF-16 string

CSS3 box-shadow + inset + RGBA

家住魔仙堡 提交于 2019-12-10 18:05:52
问题 I'm doing some tests with new features of CSS3, but this combination only works in lastest versions of Chrome and Firefox, but not in Safari or Opera: box-shadow: inset 0px -10px 20px 0px rgba(0, 0, 0, 0.5); -webkit-box-shadow: inset 0px -10px 20px 0px rgba(0, 0, 0, 0.5); -moz-box-shadow: inset 0px -10px 20px 0px rgba(0, 0, 0, 0.5); I really don't know if they fails in the box-shadow itself, in the inset parameter, or in RGBA color. It's a syntax error or simply Safari and Opera lacks on this

Cakephp Helpers in Views and $this

天涯浪子 提交于 2019-12-10 17:47:46
问题 I'm trying to determine what the best standard is for using helpers in views whether is should be echo $form->input(); or echo $this->Form->input(); In the CakePHP manual ver 1.2 the Helper class is accessed by the helper object directly, whereas in the 1.3 book the helper object is accessed through the View. Does this matter? Leo 回答1: It really only matters because of the possibility of having a collision that will "wipe out" your access to the helper. Say I had a model named Form and

Why does const_cast need to state what you're casting to?

梦想的初衷 提交于 2019-12-10 17:39:54
问题 According to the standard (§5.2.11) a const_cast casts away cv-qualifiers (const or volatile). Here's a simple example. First you declare two functions taking a pointer and a reference: class Bar { ... }; void foo_ptr(Bar*); void foo_ref(Bar&); then you create a reference-to-const: Bar b; const Bar& cb = b; and then you can call either function by using the appropriate const_cast: foo_ptr(const_cast<Bar*>(&cb)); foo_ref(const_cast<Bar&>(cb)); Here's my question: since const_cast cannot do

PHP short open tag vs long open tag [duplicate]

狂风中的少年 提交于 2019-12-10 17:35:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Are PHP short tags acceptable to use? Which is better to use, or considered better practice: <?php or <? . I've always wanted to know. Or is it more of a preference for the programmer. 回答1: <?php is the official standard. I've never encountered a problem where a browser was confused, but just using <? can also declare XML and might not be the best habit to form. I'll tell you this though - other programmers will

Floating point exceptions - gcc bug?

▼魔方 西西 提交于 2019-12-10 17:27:39
问题 Consider the following code: #include <fenv.h> #include <stdio.h> int main() { #pragma STDC FENV_ACCESS ON 1.0/0.0; printf("%x\n", fetestexcept(FE_ALL_EXCEPT)); } I would expect it to print a nonzero value corresponding to FE_DIVBYZERO , but it prints 0. Changing the second line of main to double x = 1.0/0.0; gives the expected behavior. Is this permitted, or is it a bug? Edit: For what it's worth, at first it may seem that in most real-world code, the operations which might cause fenv

Does the C standard define a stack overflow behavior?

こ雲淡風輕ζ 提交于 2019-12-10 17:22:20
问题 Is there a defined behavior for handling a stack overflow? Apart from terminating the process, it doesn't seem like there's a whole lot that can be done. I'm just wondering if anyone might know what the C standard has to say about it. 回答1: The standard does not require the use of a stack, and has nothing to say about stack overflows. 回答2: The C99 standard doesn't define a stack; it only discusses automatic or allocated storage in the abstract, whereas a contiguous stack with overflow

What does it mean to declare a variable with a storage class specifier but no type specifier?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 16:48:52
问题 After reading through the ANSI C Yacc grammar specification I noticed the following are all valid: register x; auto y; static z; extern q; This seems strange to me, as my understanding of type would suggest that none of these variables have a type. What do these mean? How are they type checked? How much memory is allocated? 回答1: Before C99 if a type was not specified it defaulted to int this was supposed to be removed in C99 but many compilers support it even in C99 mode. For example in clang

Does the standard specify what headers include other headers?

折月煮酒 提交于 2019-12-10 16:48:50
问题 I was doing a online coding contest and my idea was to find a header which has a shorter name than <iostream> but includes <iostream> . Well, I didnt suceed until now, but this made me wonder: Does the standard specify what headers include other headers? For example, on <iostream> cplusplus states: Including this header may automatically include other headers, such as <ios> , <streambuf> , <istream> , <ostream> and/or <iosfwd> . However, when I look for <ios> there is no such statement as