Stack Overflow Weekly Newsletter
Stack Overflow Weekly Newsletter

Top new questions this week:

Weird enum in destructor

Currently, I am reading the source code of Protocol Buffer, and I found one weird enum codes defined here ~scoped_ptr() { enum { type_must_be_complete = sizeof(C) }; delete ptr_; } ...

c++ enums  
asked by zangw 65 votes
answered by Mohit Jain 66 votes

Why are async state machines classes (and not structs) in Roslyn?

Let’s consider this very simple async method: static async Task myMethodAsync() { await Task.Delay(500); } When I compile this with VS2013 (pre Roslyn compiler) the generated state-machine is ...

c# .net roslyn  
asked by gregkalapos 56 votes
answered by Damien_The_Unbeliever 62 votes

Is having a return statement just to satisfy syntax bad practice?

Consider the following code: public Object getClone(Cloneable a) throws TotallyFooException { if (a == null) { throw new TotallyFooException(); } else { try { ...

java return try-catch  
asked by yitzih 54 votes
answered by Kayaman 104 votes

Could it be the case that sizeof(T*) != sizeof(const T*)?

I'm arguing with my boss about this. They say "Yes they can be different." Is it possible that sizeof(T*) != sizeof(const T*) for a type T?

c++ language-lawyer  
asked by P45 Imminent 53 votes
answered by hvd 69 votes

C vs C++ struct alignment

I've been asked in a recent interview about C++ struct fields alignment and theoretized that C and C++ follows the same strategy in struct packing. Hovewer, it was the wrong assumption. The ...

c++ c pointers struct object-layout  
asked by Minor Threat 47 votes
answered by Sam Cristall 55 votes

In C++, should I bother to cache variables, or let the compiler do the optimization?

Consider the following code (p is of type unsigned char* and bitmap->width is of some integer type, exactly which is unknown and depends on which version of some external library we're using): for ...

c++ optimization  
asked by Yaron Cohen-Tal 39 votes
answered by YSC 33 votes

Why is the Big-O complexity of this algorithm O(n^2)?

I know the big-O complexity of this algorithm is O(n^2), but I cannot understand why. int sum = 0; int i = 1; j = n * n; while (i++ < j--) sum++; Even though we set j = n * n at the ...

algorithm big-o time-complexity complexity-theory  
asked by Omar N 33 votes
answered by Miljen Mikic 92 votes

Greatest hits from previous weeks:

How can I make a redirect page using jQuery?

How can I redirect the user from one page to another using jQuery?

javascript jquery redirect  
asked by venkatachalam 4332 votes
answered by Ryan McGeary 7612 votes

Loop through array in JavaScript

In Java you can use a for() loop to go through objects in an array like so: String[] myStringArray = {"Hello","World"}; for(String s : myStringArray) { //Do something } Can you do the same in ...

javascript arrays for-loop  
asked by Mark Szymanski 1179 votes
answered by CMS 1780 votes

Can you answer these?

Ruby: modules extending/including modules

I'm trying to better understand how modules extend and include each other. Say I have module A: module A def learned_from_A true end end A.instance_methods # [:learned_from_A] I mix its ...

ruby module extend  
asked by ivan 7 votes

What is the proper JSDOC syntax for referencing imported es6 classes?

I'm trying to figure out proper syntax for specifying external classes as params/returns in JSDOC. so, for example, I have: import redux from 'redux'; /** * @param {object} state * @return ...

javascript ecmascript-6 webstorm jsdoc commonjs  
asked by JimiDini 5 votes

Incorrect double to long conversion

This is mainly a followup to this other question, that was about a weird conversion from long to double and back again to long for big values. I already know that converting a float to an integral ...

c++ visual-c++  
asked by Serge Ballesta 7 votes
Subscribe to more Stack Exchange newsletters

Unsubscribe from this newsletter or change your email preferences by visiting your subscriptions page on

Questions? Comments? Let us know on our feedback site. If you no longer want to receive mail from Stack Exchange, unsubscribe from all emails.

Stack Exchange, Inc. 110 William St, 28th Floor, NY NY 10038 <3