All Questions

Tagged with
Filter by
Sorted by
Tagged with
403 votes
19 answers
281k views

How to round up the result of integer division?

I'm thinking in particular of how to display pagination controls, when using a language such as C# or Java. If I have x items which I want to display in chunks of y per page, how many pages will be ...
Ian Nelson's user avatar
  • 58.1k
317 votes
29 answers
237k views

How much faster is C++ than C#?

Or is it now the other way around? From what I've heard there are some areas in which C# proves to be faster than C++, but I've never had the guts to test it by myself. Thought any of you could ...
Trap's user avatar
  • 12.2k
300 votes
5 answers
121k views

What do 'statically linked' and 'dynamically linked' mean?

I often hear the terms 'statically linked' and 'dynamically linked', often in reference to code written in C, C++ or C#. What are they, what exactly are they talking about, and what are they linking?
UnkwnTech's user avatar
  • 89.5k
224 votes
22 answers
63k views

Why does C# not provide the C++ style 'friend' keyword? [closed]

The C++ friend keyword allows a class A to designate class B as its friend. This allows Class B to access the private/protected members of class A. I've never read anything as to why this was left ...
Ash's user avatar
  • 61.6k
208 votes
11 answers
87k views

How to get started with developing Internet Explorer extensions?

Does anyone here have experience with/in developing IE extensions that can share their knowledge? This would include code samples, or links to good ones, or documentation on the process, or anything. ...
Alex's user avatar
  • 65.2k
203 votes
13 answers
61k views

What are the differences between Generics in C# and Java... and Templates in C++? [closed]

I mostly use Java and generics are relatively new. I keep reading that Java made the wrong decision or that .NET has better implementations etc. etc. So, what are the main differences between C++, C#,...
pek's user avatar
  • 18k
194 votes
19 answers
237k views

Naming convention - underscore in C++ and C# variables

It's common to see a _var variable name in a class field. What does the underscore mean? Is there a reference for all these special naming conventions?
Stan's user avatar
  • 37.7k
188 votes
52 answers
68k views

Why is it considered a bad practice to omit curly braces? [closed]

Why does everyone tell me writing code like this is a bad practice? if (foo) Bar(); //or for(int i = 0 i < count; i++) Bar(i); My biggest argument for omitting the curly braces is that ...
182 votes
15 answers
425k views

What does void mean in C, C++, and C#?

Looking to get the fundamentals on where the term "void" comes from, and why it is called void. The intention of the question is to assist someone who has no C experience, and is suddenly looking at a ...
Nick Katsivelos's user avatar
179 votes
9 answers
254k views

Kill some processes by .exe file name

How can I kill some active processes by searching for their .exe filenames in C# .NET or C++?
Aliasghar Yaghoobzadeh's user avatar
178 votes
12 answers
197k views

How can I specify a [DllImport] path at runtime?

In fact, I got a C++ (working) DLL that I want to import into my C# project to call it's functions. It does work when I specify the full path to the DLL, like this : string str = "C:\\Users\\...
Jsncrdnl's user avatar
  • 3,045
169 votes
11 answers
19k views

Why does the default parameterless constructor go away when you create one with parameters

In C#, C++ and Java, when you create a constructor taking parameters, the default parameterless one goes away. I have always just accepted this fact, but now I've started wondering why. What is the ...
olagjo's user avatar
  • 2,135
163 votes
12 answers
18k views

Never seen before C++ for loop

I was converting a C++ algorithm to C#. I came across this for loop: for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = v; It gives no error in C++, but it does in C# (cannot convert int to ...
Thomas's user avatar
  • 2,070
155 votes
20 answers
518k views

Unable to load DLL (Module could not be found HRESULT: 0x8007007E)

I have a dll library with unmanaged C++ API code I need to use in my .NET 4.0 application. But every method I try to load my dll I get an error: Unable to load DLL 'MyOwn.dll': The specified module ...
Ingimar Andresson's user avatar
135 votes
13 answers
179k views

Cannot find Dumpbin.exe

I do not see dumpbin.exe on my system. I have Visual Studio 2005 on my system. When I type dumpbin on the command line, it says unrecognizable command. Does it come with Visual Studio by default, or ...
user avatar
123 votes
13 answers
9k views

How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?

In a recent interview, I was asked a really strange question. The interviewer asked me how can I compute 1+2+3+...+1000 just using compiler features. This means that I am not allowed to write a ...
TonySalimi's user avatar
  • 8,385
119 votes
31 answers
444k views

C++ performance vs. Java/C#

My understanding is that C/C++ produces native code to run on a particular machine architecture. Conversely, languages like Java and C# run on top of a virtual machine which abstracts away the native ...
117 votes
31 answers
148k views

'do...while' vs. 'while'

Possible Duplicates: While vs. Do While When should I use do-while instead of while loops? I've been programming for a while now (2 years work + 4.5 years degree + 1 year pre-college), and I've ...
mphair's user avatar
  • 1,460
116 votes
16 answers
90k views

Does C++11 have C#-style properties?

In C#, there is a nice syntax sugar for fields with getter and setter. Moreover, I like the auto-implemented properties which allow me to write public Foo foo { get; private set; } In C++ I have to ...
Radim Vansa's user avatar
  • 5,808
112 votes
19 answers
29k views

What is the fastest way to compute sin and cos together?

I would like to compute both the sine and co-sine of a value together (for example to create a rotation matrix). Of course I could compute them separately one after another like a = cos(x); b = sin(x);...
Danvil's user avatar
  • 22.6k
111 votes
18 answers
218k views

What's the best way to do a backwards loop in C/C#/C++? [closed]

I need to move backwards through an array, so I have code like this: for (int i = myArray.Length - 1; i >= 0; i--) { // Do something myArray[i] = 42; } Is there a better way of doing this? ...
MusiGenesis's user avatar
  • 74.8k
107 votes
14 answers
29k views

Why should casting be avoided? [closed]

I generally avoid casting types as much as possible since I am under the impression that it's poor coding practice and may incur a performance penalty. But if someone asked me to explain why exactly ...
LoudNPossiblyWrong's user avatar
104 votes
11 answers
62k views

Equivalent of #region for C++

What's the C++ equivalent of #region for C++ so I can put in custom code collapsible bits and make my code a little easier to read?
Dollarslice's user avatar
  • 10.1k
101 votes
4 answers
218k views

C# equivalent of C++ vector, with contiguous memory?

What's the C# equivalent of C++ vector? I am searching for this feature: To have a dynamic array of contiguously stored memory that has no performance penalty for access vs. standard arrays. I was ...
edgarmtze's user avatar
  • 24.9k
99 votes
7 answers
127k views

Possible to call C++ code from C#?

Is it possible to call C++ code, possibly compiled as a code library file (.dll), from within a .NET language such as C#? Specifically, C++ code such as the RakNet networking library.
user avatar
97 votes
16 answers
63k views

What does the unary plus operator do?

What does the unary plus operator do? There are several definitions that I have found (here and here) but I still have no idea what it would be used for. It seems like it doesn't do anything but there ...
vrish88's user avatar
  • 20.7k
97 votes
11 answers
5k views

Efficiency of premature return in a function

This is a situation I encounter frequently as an inexperienced programmer and am wondering about particularly for an ambitious, speed-intensive project of mine I'm trying to optimize. For the major C-...
Philip Guin's user avatar
  • 1,451
90 votes
11 answers
62k views

Can I get Memcached running on a Windows (x64) 64bit environment?

Does anyone know IF, WHEN or HOW I can get Memcached running on a Windows 64bit environment? I'm setting up a new hosting solution and would much prefer to run a 64bit OS, and since it's an ASP.Net ...
RobertTheGrey's user avatar
86 votes
5 answers
24k views

What does stream mean? What are its characteristics?

C++ and C# both use the word stream to name many classes. C++: iostream, istream, ostream, stringstream, ostream_iterator, istream_iterator... C#: Stream, FileStream,MemoryStream, BufferedStream... ...
Kashif's user avatar
  • 2,984
86 votes
7 answers
70k views

C++ union in C#

I'm translating a library written in C++ to C#, and the keyword 'union' exists once. In a struct. What's the correct way of translating it into C#? And what does it do? It looks something like this; ...
Viktor Elofsson's user avatar
85 votes
12 answers
33k views

Is C# really slower than say C++?

I've been wondering about this issue for a while now. Of course there are things in C# that aren't optimized for speed, so using those objects or language tweaks (like LinQ) may cause the code to ...
Yochai Timmer's user avatar
84 votes
6 answers
121k views

using a class defined in a c++ dll in c# code

I have a dll that was written in c++, I need to use this dll in my c# code. After searching I found that using P/Invoke would give me access to the function I need, but these functions are defined ...
Dan Vogel's user avatar
  • 3,918
83 votes
5 answers
82k views

pinvokestackimbalance -- how can I fix this or turn it off?

I just switched to vs2010 from vs2008. Exact same solution, except now every single call to a C++ dll yields a 'pinvokestackimbalance' exception. This exception does not get fired in 2008. I have ...
mmr's user avatar
  • 14.8k
80 votes
10 answers
250k views

Visual Studio /**/ comment shortcut?

I want to know how to put the /**/ comments through shortcut. I know the Ctrl+K+C shortcut for the // comments but it comments the whole line. Sometimes while debugging, I want to do something like "...
Zia Khattak's user avatar
80 votes
11 answers
153k views

Foreach loop in C++ equivalent of C#

How would I convert this code to C++? string[] strarr = {"ram","mohan","sita"}; foreach(string str in strarr) { listbox.items.add(str); }
Swapnil Gupta's user avatar
79 votes
4 answers
239k views

What is C# equivalent of <map> in C++? [duplicate]

I have defined a class myComplex. I need to map it to integers. In C++ I would have created a map as map<myComplex,int> first; How to do such thing in C#?
Abhash Kumar Singh's user avatar
75 votes
23 answers
69k views

How do you flag code so that you can come back later and work on it?

In C# I use the #warning and #error directives, #warning This is dirty code... #error Fix this before everything explodes! This way, the compiler will let me know that I still have work to do. What ...
72 votes
6 answers
81k views

What are the definitions for LPARAM and WPARAM?

I know I'm being lazy here and I should trawl the header files for myself, but what are the actual types for LPARAM and WPARAM parameters? Are they pointers, or four byte ints? I'm doing some C# ...
Mark Heath's user avatar
  • 48.9k
71 votes
2 answers
23k views

Why are Cdecl calls often mismatched in the "standard" P/Invoke Convention?

I am working on a rather large codebase in which C++ functionality is P/Invoked from C#. There are many calls in our codebase such as... C++: extern "C" int __stdcall InvokedFunction(int); With a ...
Kadaj Nakamura's user avatar
68 votes
18 answers
13k views

How much null checking is enough?

What are some guidelines for when it is not necessary to check for a null? A lot of the inherited code I've been working on as of late has null-checks ad nauseam. Null checks on trivial functions, ...
James Schek's user avatar
  • 17.9k
67 votes
4 answers
87k views

How do I call C++/CLI from C#?

I have a class implemented in C++ that's responsible for the arithmetic computation of the program, and an interface using WPF. I process the input with C# but then how can I use my C++ class? I've ...
master chief's user avatar
66 votes
2 answers
87k views

Passing strings from C# to C++ DLL and back -- minimal example

I am trying to make the absolute simplest minimal example of how to pass strings to and from a C++ DLL in C#. My C++ looks like this: using std::string; extern "C" { string concat(string a, ...
asutherland's user avatar
  • 2,909
65 votes
6 answers
97k views

How to call a C# library from Native C++ (using C++\CLI and IJW)

Background: As part of a larger assignment I need to make a C# library accessible to unmanaged C++ and C code. In an attempt to answer this question myself I have been learning C++/CLI the past few ...
amalgamate's user avatar
  • 2,230
64 votes
6 answers
18k views

Pre & post increment operator behavior in C, C++, Java, & C# [duplicate]

DISCLAIMER: This is not a real-world example. It is just a theoretical question of how these languages work. What exactly are the differences between C/C++, C#, and Java when it comes to post &...
Nick's user avatar
  • 5,785
58 votes
5 answers
87k views

Is dependency injection useful in C++

C# uses Dependency Injection (DI) a lot to have a lossless and testable platform. For this, I need an interface and maybe a DI or Inversion of Control (IoC) container for resolving my instances. But ...
Marcel Hoffmann's user avatar
57 votes
2 answers
6k views

Why is "using System;" not considered bad practice?

I have a C++ background and I do fully understand and agree with the answers to this question: Why is “using namespace std;” considered bad practice? So I'm astonished that, having some experience ...
sebrockm's user avatar
  • 5,853
56 votes
6 answers
80k views

Ease-in and ease-out animation formula

Say, if I'm doing the Ease-Out and then Ease-In animation of an object's movement from X1 coordinate to X2 coordinate over S steps at equal time intervals. Can some suggest the formula to calculate ...
ahmd0's user avatar
  • 17k
55 votes
5 answers
107k views

Is there pointer in C# like C++? Is it safe?

I'm writing an application that work with a tree data structure. I've written it with C++, now i want to write it by C#. I use pointers for implementing the tree data structure. Is there a pointer in ...
masoud ramezani's user avatar
54 votes
31 answers
7k views

Technical reasons behind formatting when incrementing by 1 in a 'for' loop?

All over the web, code samples have for loops which look like this: for(int i = 0; i < 5; i++) while I used the following format: for(int i = 0; i != 5; ++i) I do this because I believe it to ...
54 votes
8 answers
7k views

Code with undefined behavior in C#

In C++ there are a lot of ways that you can write code that compiles, but yields undefined behavior (Wikipedia). Is there something similar in C#? Can we write code in C# that compiles, but has ...
luvieere's user avatar
  • 37.2k

1
2 3 4 5
218