It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Can any body tells me what are the reasons of program crash when somebody divide some thing by zero in c++.
The best "reason" is that, per the language, division by zero is undefined behavior, so anything could happen. A crash is the most useful "anything" to the programmer since it helps you catch the bug.
As for why the C++ language left division by zero undefined, that probably comes from C which does the same, and in turn from the facts that (1) there is no mathematical definition, and (2) different hardware might do different things when dividing by zero, and since there's no reason a valid program should be making the division by zero, it's not worth adding an emulation/patch-up layer around every division to force a common behavior on all platforms.
Division by zero is mathematically undefined, it has nothing to do with c++ or any other language.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I was working on a factorial program, and the program didn't work when trying to find the factorial of 1000. I think big integers are the solution; how do they work? (In either C or C++)
GMP can do bigint operations for both C and C++. The documentation on that site is a good introduction, if you use the C++ classes they behave almost exactly like built-in primitive types.
Look for the GMP. See the other question regarding this topic:
Handling very large Integers
C++ Big Integer
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am aware about the risks on race conditions and that values written or read might be corrupted. I am in a situation where I have races on boolean and integers and a couple of classes instance.
Could this lead to a program crash, or any other nasty effect on my program aside from the data not being valid? Do I have worry for the worst?
I have 2 versions of my program a debug and another with a lot of options for optimization. I am worried about this last one as it goes to production.
data not being valid may result in anything (i.e. you invoke undefined behavior). So having that in mind your application may crash, leak memory, format you hard drive and almost anything else.
Could this lead to a program crash
Depends on the resource being raced for, but yes. If one thread grabs the resource and another thread needs it to progress, you can get undefined behavior and even program crashes.
any other nasty effect on my program aside from the data not being valid?
Aside from invalid data (thus a practically useless program), you could also be prone to deadlocks.
The wikipedia article on race condition is a good place to find answers to questions such as these.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have come across loop-unrolling but what other types of compiler optimization are there for C++ code?
If possible, I'd be interested specifically for the Intel Compiler and GNU Compiler.
If I could obtain a list I can google for the explanation upon each type of optimization.
if you are talking generically, beyond loop unrolling, there is also the basic:
remove unchanging variables out of a loop.
optimizing away unused but initialized objects/variables/instances.(dead code removal)
expanding function calls in line, like strlen();
using processor specific directives/commands.
thats off the top of my head... I will be back with some scientific (wikipedia lol) answers
heres more:
5. static variable inlining
6. complex branch optimization
ok, tired lol heres a decent link i was just looking at :)
http://www.eetimes.com/electronics-products/embedded-tools/4086427/Advanced-Compiler-Optimization-Techniques
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
A really basic question:
Considering an unsigned integer value, we would like to check that is not equal to 0. Using != or >, which one would be more efficient to use in C++?
Is your application too slow? If it is, the first thing you should do is profile -- this will show you what is causing your program to be slow.
If you aren't having efficiency issues with your program then you shouldn't be worried about this. In fact, worrying about speed at this stage is a bad thing because often people write less readable code in an attempt to improve speed when it's not even an issue.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
My Question is related to this as I solved the problem, I wrote my own sorting algorithm (a simple insertion sort), and it works. I am quite surprised by this as I thought that the standard library is well-tested. Are there any known special cases in which std::sort might mess up?
No, it's highly unlikely that there are any known bugs in any of the common C++ standard library implementations of std::sort. It's rigorously tested.
If you see a crash or incorrect results, it's almost certainly because you didn't adhere to the contract: either you passed in invalid arguments, or your comparator does not obey the requirements for a strict weak ordering (irreflexivity, asymmetry, transitivity, and transitivity of equivalence).
If your comparison function/object doesn't follow a strict weak ordering, or the thing you're sorting contains pointers that are no longer valid, either of those could cause it to break.