Today, I encountered the need to use qsort function in the force deduction problem. As a result, there was no test case. The error reports are as follows
signed integer overflow: 0 – -2147483648 cannot be represented in type ‘int
Signed integer overflow: 0 — 2147483648 cannot be represented in type ‘Int’
The error was reported in the CMP function. At that time, I wondered if it was still within the range. I thought about it and found the problem
This is my original CMP function
int cmp(const void *a,const void *b){
return (*(const int*)a > *(const int*)b);
}
At this time, a is – 2147483648. Subtract B. as long as B is greater than 0, it overflows
terms of settlement:
Change the minus sign to the greater than sign
int cmp(const void *a,const void *b){
return (*(const int*)a > *(const int*)b);
}
So it passed smoothly.
There are few questions about this on the Internet. Maybe it’s too stupid. Send a post to help Xiaobai like me
Read More:
- The function and usage of argc and argv in C language
- error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
- Running realsense ROS reports an error, USB cam overflow, hardware error
- C language write() function analysis: write failed bad address
- When C language refers to a user-defined type as a parameter, an error segmentation fault is reported
- [OpenGL · error] visual studio 2019 reports an error. It is an external symbol gladloadglloader that cannot be parsed. This symbol is referenced in the function main
- C language string processing error warning, c4996, sprintf, predicted, c4996, strcpy, c4996, strcat
- Imshow() reports an error after C + + opencv 4.5.1 configures the environment
- PHP function file_ get_ Contents() reports an error when using HTTPS protocol: SSL operation failed
- Python calls C to generate so library and reports an error: undefined symbol
- Unit Android converts c# class to JSON file and reports an error
- Error c2137 of C language: empty character constant (Fixed)
- Hadoop reports an error. Cannot access scala.serializable and python MapReduce reports an error
- C++: terminate called after throwing an instance of ‘std::length_error‘ (sort function cmp sorting rules problem)
- HTML method IE8 reports an error, IE8 jQuery Ajax obtains static resources reports an error, typeerror denies access
- R language notes – sample() function
- The echots in Vue reports an error. After obtaining the DOM element, the chart can be displayed. The console still reports an error
- The file server reports an error of 413, and the file uploaded by nginx reports an error of 413 request entity too large
- On the coercion of C language
- C / C + + rounding function: round function