C++ :: Overflow / Underflow Detecting Functions
Sep 15, 2014
I am performing arithmetic operations on very large integers that operate around the threshold of the maximum positive integer an int variable can handle (i.e. 2147483647) for a 32-bit machine. I have been studying the in-built functions in the C++ Standard Library for some time now where I came across some error detecting functions in the <cmath> and <cerrno> header files. The impression I got from the literature is that they are solely used in conjunction with functions contained in the <cmath> header file and not necessarily with fundamental arithmetic operations like addition and subtraction.
I need a means to know when my arithmetic operations generate overflows/underflows! Is there any way I can adapt the functionalities of these functions to my needs?
View 5 Replies
ADVERTISEMENT
Feb 3, 2012
I have source code that is shared between two compilers, one supports TR1 and one doesn't. I've reverse engineered a few of the TR1 templates for the older compiler, but I need to be able to detect whether TR1 is supported or not, so as to include the correct header.
Something like this.
Code:
#ifdef SUPPORTS_TR1
#include <array>
#else
#include "mystl/array"
#endif
std::array<int, 10> myarray;
The compiler that supports TR1 is Visual Studio.
View 2 Replies
View Related
Jul 16, 2014
Say a user installs and uses the software for awhile. Then they uninstall it. Client wants the database containing client data to remain behind, in case they ever re-install the software. Which is fine.
So then.. they re-install the software. Client wants them to have the choice to either use the existing database, or to create a new one. When the software fires up, it always checks for the database, and creates one if it's not there. So how can I determine if the instance is a new install, or a current install, given that the database will be there no matter what?
View 7 Replies
View Related
May 24, 2014
I was just wondering how to deal with overflow. My code works for exponential when i put small numbers in like 2 and 3. So it would do 2^3 which would be 8. But if i try something like 2^44 then I just get 0.
View 2 Replies
View Related
Jan 21, 2014
I have a direct2d application and I want to be able to detect mouse clicks. One example is, (in my borderless window) I would like to have an X at the top right of the screen, that when clicked would close the window. How can I do something like this?
View 3 Replies
View Related
Jul 2, 2013
Code:
#include "opencv2/video/tracking.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <stdio.h>
#include <stdlib.h>
[Code] ....
The above code is all I have so far. I got confused when I got to the part where my book on C tells me I need to use the cvCalcOpticalFlowFarneback() function to compare 2 consecutive images from the webcam and create the optical flow, and then measure movement between the frames to detect whether or not a person is moving through the room. How to do this, and the OpenCV wiki wasn't very descriptive on how to set it up for beginners. Honestly, the parameters just confused me and I didn't see a return value listed, or how you would get data from it.
View 8 Replies
View Related
Mar 20, 2014
Just wrote this extremely simple program but it seems to be malfunctioning. It counts correctly the number of uppercase letters in a string so long as i don't use the space-bar. once I add a space it only counts the number of uppercase letters of the first word..
printf("I ..........ing love programming");
Code:
#include <stdio.h>
main()
{
char text[200];
int i = 0;
int uppercase = 0;
printf("Enter text:");
scanf("%s", text);
[code]....
View 6 Replies
View Related
Sep 22, 2013
I'm getting a stack overflow error because for large numbers, this code I'm working on allocates too much on the stack.
Is there a way of tracking stack allocations specifically?
Will multithreading solve my problem if each thread is doing the static allocations?
Would I really have to use malloc or new every time I wanted to use memory just to make my code scale to huge numbers?
View 11 Replies
View Related
Sep 19, 2013
I usually check if a bit is set using:
Code: bit = (number >> n) & 1; where `n` is the bit I want to check...
But I came across a stackoverflow answer saying:
bit = number & (1 << x); will not put the value of bit x into bit unless bit has type _Bool (<stdbool.h>).
Otherwise, bit = !!(number & (1 << x)); will..
So why is this? why the double !?
View 5 Replies
View Related
Jun 5, 2013
Here is my error message: Warning1warning C4717: 'getx' : recursive on all control paths, function will cause runtime stack overflow
and here is my code I will Bold the part that is giving me problems!
class point
{
public:
point();
[Code]....
View 5 Replies
View Related
Jun 20, 2014
I am trying to detect keys pressed on a keyboard and mouse on both, Windows and Linux but I am unsure what would be the best practice way to do so. Will I have to detect the keys for each platform individually? Would you make use of an event listener? What's the best way to detect the input-devices?
View 1 Replies
View Related
Jul 8, 2014
I would like the user to insert a CD into their computer and click on an button on my application that allows them to read the CD-ROM and find a specific file type, e.g. csv, and then grab the info in the csv file.
I already have my StreamReader setup grabbing a filepath.
Now I am just wondering...how do I detect the CD-ROM and how do I grab the filepath of the only CSV file on the CD-ROM?
What's behind detecting a CD-ROM and grabbing a specific file type from a CD-ROM?
I heard about DriveInfo
However, that only allows me to detect a drive but not look at it's contents.
View 14 Replies
View Related
Jun 3, 2013
I need use GetTextExtent and I don't understant why GetTextExtent always return the same value if I change some values of the selected font. This is my example:
Code:
LOGFONT lf;
pOldFont->GetLogFont(&lf);
CString sExampleSizeByChar;
sExampleSizeByChar = _T("hello");
DWORD dwPixelsByChar = dc.GetTextExtent(sExampleSizeByChar).cx / 1.15;
[Code] ....
Why I get always the value 24 when I call GetTextExtent if I change the font size?
View 3 Replies
View Related
Feb 1, 2013
How do I detect garbage chars in a CString. Actually I'm reading some data from COM port. In some certain condition it will give some garbage as a version no. Now I need to show _T("N/A") in case of there is any garbage.
My solution is to check for a Valid char or integer. If found its correct else Garbage.
View 11 Replies
View Related
Apr 20, 2012
I have written ( using VS2008 c++ ) a windows service which sends information about PC usage to a central database, as part of a PC availability setup. I have been asked to add the following functionality to it:
1) What applications are most used, when and how long for, and
2) What web sites are being accessed, again to find the most popular etc.
My main question is, what functionality is there to trap application start / close events from within my service ( just need the application name ), and secondly I am already using sockets to send information to a PHP script on a server, the best way to see what web pages are being accessed is to build in a packet sniffer, and extract the information from that.
View 6 Replies
View Related
Jan 3, 2014
Code:
char buffer1[10];
char buffer2[10] = "something";
sprintf(buffer1, "with %s", buffer2);
In a statement like the one above, is there a threat/leak or does it only truncate the string that is loaded into buffer1?
View 5 Replies
View Related
Jul 11, 2013
Small code to show overflow...But when I compile and run - buffer_one is not being overwritten when the byte size of buffer_two overflows .
Code:
#include <stdio.h>#include <string.h>
int main(int argc, char *argv[]) {
int value = 5;
char buffer_one[8], buffer_two[8];
strcpy(buffer_two, "two"); //Put "one" into buffer_one
strcpy(buffer_one, "one"); //Put "two" into buffer_two
}
[code]....
View 3 Replies
View Related
Jun 9, 2013
After not programming for sometimes I decided to program a small application. But I have some trouble according to what I remember and re-checking arrays online. I don't understand how the code I wrote below is possible, shouldn't give a stack overflow error or something to that extent? Instead it gives me the value of 3.
#include "stdafx.h"
#include<iostream>
int _tmain(int argc, _TCHAR* argv[]) {
int arr2 [2];
arr2 [3] = 3;
[Code] ....
View 1 Replies
View Related
Sep 10, 2013
I'm pretty new to C, and keep getting an error. Basically I'm trying to convert a ppm image to all red. Here is my code that I can't get to work:
Code:
change(pixel_t *PIXEL, &w, &h,pixel_t *buffer);
And here is the beginning of my convert function:
Code:
void change(pixel_t *pixel, int w, int h, pixel_t *buffer) {
int average, sum;
int i;
pixel_t *pointer;
Everything else works fine. I keep getting an error when I call the convert function. It says "expected expression before pixel_t" and "too few arguments to function "change". I know that everything else in the main is working.
View 3 Replies
View Related
Sep 21, 2013
preventing a buffer overflow when dealing with strings being passed as arguments.
If I have a function prototype such as:
Code:
void foobar(char *bar);
That argument bar - is intended to take a pointer to a buffer of x characters in length. Inside that function, I can't get the size of that buffer, as bar is now just a pointer to a char. I COULD just make the user of this function pass a length parameter, but there is no guarantee that would be correct. Is there a bullet proof way of detecting that the user has provided a buffer that is too small?
View 11 Replies
View Related
Feb 16, 2014
How do I detect left mouse button down and up events on the 'Close' option of the system menu that appears when the mouse is clicked on the top left corner of a form?
View 1 Replies
View Related
Mar 26, 2013
I am trying to implement the insert function of a binary tree. Atm when I try and insert 3 nodes, the program breaks and gives me a stack overflow error. The error points to a getter function for an identifier for the data in my node class.
void LinkedList::add(Product *myProduct) {
if (_length==0) {
_head = new Node(NULL, NULL, myProduct);
_end = _head;
_length=1;
[Code] ....
Here is my insert function, the error message is
"An unhandled exception of type 'System.NullReferenceException' occurred in SDI2.exe
Additional information: Object reference not set to an instance of an object. "
In my main I have declared an instance of product, "productToAdd = new Product(id,idPrice);" so I'm a bit confused as to what I need to include..
View 3 Replies
View Related
Apr 22, 2012
Why I have a
HTML Code:
FLOATING POINT ERROR: OVERFLOW
ABNORMAL PROGRAM TERMINATION
in the code below?
Code:
#include<stdio.h>
#include <math.h>
#include<conio.h>
#define A 0
#define B 1
float F(float x0, float y0) {
return (0.2*x0)+(y0*y0);
[Code] .....
View 7 Replies
View Related
May 8, 2012
What is wrong with this code? I keep getting
HTML Code:
FLOATING POINT ERROR: OVERFLOW
ABNORMAL PROGRAM TERMINATION
Code:
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<iostream.h>
#define N 4
float x[5]={0, 1, 2, 3, 4};
float y[5]={0.5, 2, 7.5, 20, 42.5};
[Code] ....
View 2 Replies
View Related
Mar 20, 2014
I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.
We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.
As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.
NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.
Stack.h
#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;
[Code]...
View 3 Replies
View Related
May 3, 2013
At the moment im trying out with pointing to an array of functions. I got this working as following:
typedef void (* functionPtr) ();
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}
void loop(){
A=0;
B=1;
functions[A][b]();
}
But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:
error: argument of type 'void (Basic::)()' does not match 'void (*)()'
View 2 Replies
View Related