standards

Potential problem with C standard malloc'ing chars

本小妞迷上赌 提交于 2019-11-29 15:09:17
问题 When answering a comment to another answer of mine here, I found what I think may be a hole in the C standard (c1x, I haven't checked the earlier ones and yes, I know it's incredibly unlikely that I alone among all the planet's inhabitants have found a bug in the standard). Information follows: Section 6.5.3.4 ("The sizeof operator") para 2 states "The sizeof operator yields the size (in bytes) of its operand" . Para 3 of that section states: "When applied to an operand that has type char,

Why must I use address-of operator to get a pointer to a member function?

落爺英雄遲暮 提交于 2019-11-29 14:06:41
struct A { void f() {} }; void f() {} int main() { auto p1 = &f; // ok auto p2 = f; // ok auto p3 = &A::f; // ok // // error : call to non-static member function // without an object argument // auto p4 = A::f; // Why not ok? } Why must I use address-of operator to get a pointer to a member function? auto p1 = &f; // ok auto p2 = f; // ok The first is more or less the right thing. But because non-member functions have implicit conversions to pointers, the & isn't necessary. C++ makes that conversion, same applies to static member functions. To quote from cppreference : An lvalue of function

std::allocator construct/destroy vs. placement new/p->~T()

天大地大妈咪最大 提交于 2019-11-29 14:06:34
问题 For a project of mine, I am writing some STL containers from scratch (I have my reasons). Since I am mimicking the functionality and interfaces of the STL so closely I am doing my best to keep with the policy "if it has the same name as a standard construct, it will conform to the standard as much as possible." So, of course my containers take allocators as a template parameter, which is very nice as it allows for some custom allocation schemes. On to my question. The std::allocator interface

Scope resolution operator on enums a compiler-specific extension?

这一生的挚爱 提交于 2019-11-29 14:05:21
On this question , there's an answer that states: You can use typedef to make Colour enumeration type accessible without specifying it's "full name". typedef Sample::Colour Colour; Colour c = Colour::BLUE; That sounds correct to me, but someone down-voted it and left this comment: Using the scope resolution operator :: on enums (as in "Colour::BLUE") is a compiler-specific extension, not standard C++ Is that true? I believe I've used that on both MSVC and GCC, though I'm not certain of it. I tried the following code: enum test { t1, t2, t3 }; void main() { test t = test::t1; } Visual C++ 9

JavaFX Menu - first letter, underline decoration

亡梦爱人 提交于 2019-11-29 12:21:28
问题 Following the UI standards: If application menu item (on the top menu bar) opens a dropdown, it MUST be decorated as it is shown under: The first letter has "text-decoration:underline" property. But accoring to this http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html I can't do like that in in javafx app. Any suggestions? 回答1: Background on Mnemonics What you point to in your image is a keyboard mnemonic. JavaFX does support mnemonics, but you will only see them on

Why argument type of `putchar()`, `fputc()` and `putc()` is not `char`?

只愿长相守 提交于 2019-11-29 11:55:54
Does anybody know Why argument type of putchar() , fputc() and putc() is not char , but argument type of putwchar() , fputwc() and putwc() is wchar_t ? See also this and this . The answer is 'legacy' (or 'history'). Before the C90 standard, there were no function prototypes and all arguments to all functions were subject to default promotion rules, so a char was automatically passed as an int ( short was promoted to int too, and float to double , and similarly for unsigned types). The standard couldn't afford to break existing code, so it kept that type for these functions. It makes very

Global qualification in a class declarations class-head

谁都会走 提交于 2019-11-29 11:36:44
We found something similar to the following (don't ask ...): namespace N { struct A { struct B; }; } struct A { struct B; }; using namespace N; struct ::A::B {}; // <- point of interest Interestingly, this compiles fine with VS2005, icc 11.1 and Comeau (online), but fails with GCC: global qualification of class name is invalid before '{' token From C++03, Annex A, it seems to me like GCC is right: the class-head can consist of nested-name-specifier and identifier nested-name-specifier can't begin with a global qualification ( :: ) obviously, neither can identifier ... or am i overlooking

Why doesn't the compiler detect and produce errors when attempting to modify char * string literals?

隐身守侯 提交于 2019-11-29 11:13:29
Assume the following two pieces of code: char *c = "hello world"; c[1] = 'y'; The one above doesn't work. char c[] = "hello world"; c[1] = 'y'; This one does. With regards to the first one, I understand that the string "hello world" might be stored in the read only memory section and hence can't be changed. The second one however creates a character array on the stack and hence can be modified. My question is this - why don't compilers detect the first type of error? Why isn't that part of the C standard? Is there some particular reason for this? C compilers are not required to detect the

VS2010 C and C++ - enforce ANSI compliance for Linux/gcc compatibility?

别说谁变了你拦得住时间么 提交于 2019-11-29 10:48:12
I'm taking a class in which I'm required to write some C++ apps for Linux. I really, really dislike the dev tools available under Linux, but I love VS2010. Is there any sort of compiler switch which will enforce ANSI or gcc compatibility in VC++? Or can I swap the compiler out for gcc and still use the VS environment? You can disable Microsoft extensions to the ANSI C and ANSI C++ standards by specifying the /Za flag, which will make the compiler emit errors if you use non-standard C and C++ features. http://msdn.microsoft.com/en-us/library/0k0w269d(v=VS.100).aspx However, this doesn't

Are pointers allowed as keys in ordered STL containers?

*爱你&永不变心* 提交于 2019-11-29 10:47:33
There's this other question asking about how comparing pointers is supposed to be interpreted wrt the C++ Std. So I was wondering what the C++ Std has to say about using pointers as keys in ordered standard library (STL) containers -- i.e. is one allowed to have std::map<T1*, T2> and is this due to the specification of std::less or builtin operator < ? Yes, because it uses std::less , which is required to result in a total order even if < doesn't. ( < would be allowed to treat different pointers from distinct sequences as equal, which would result in an odd behaviour of map etc if you insert