|
|
line 55
: In function `std::pair<int, int> F(const std::vector<int, std::allocator<int> >&)': 55: error: expected primary-expression before '{' token 55: error: expected `;' before '{' token Execution terminated |
In function 'std::pair<int, int> F(const std::vector<int>&)': 32:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] 38:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] 47:33: warning: suggest parentheses around assignment used as truth value [-Wparentheses] 50:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] |
size
returns a std::size_t
type, so consider making the types of variables that compare to it std::size_t
as well.==
rather than =
in a comparison.using namespace std;
, just put std::
before each std thing, believe me it's the best way and all the expert coders do it that way.line 47
(changing it from 'assignment' to 'relational') and used the C++ shell on this site to run the program. Guess what, it worked!! But for some curious reason, I still can't get it to compile on the Dev C++ compiler I use!! Guess what, it worked!! But for some curious reason, I still can't get it to compile on the Dev C++ compiler I use!! |
TheIdeasMan wrote: |
---|
size returns a std::size_t type, so consider making the types of variables that compare to it std::size_t as well. |
What could explain this strange difference in behavior? |
-Wall -Wextra -pedantic
|
|
static_cast
here? If yes, why is it necessary since all the variables in parentheses were already declared to be int
? int
variables (in the function) to size_t
in conformity to @TheIdealMan's suggestion in earlier posts. Result: the program compiled but it entered an infinite loop when I ran it!! I had to abort it manually.
|
|
j
value is 0, but the increment is --j
, so it tries to go negative straight away, but std::size_t
is unsigned. Maybe that is a logical error you have there? Line 38 attempts to access A[j]
and A[j+1]
. If the loop is decrementing, I might have expected to start at the end of the array and work down, so maybe max_length should be the size of the vector A?3. Does the Dev C++ compiler have a C++11 version? If no, what other good, stable, free C++11 editor/compilers are out there? |
https://gcc.gnu.org/ http://llvm.org/ |
std::size_t
, it wraps around, giving the maximum value - probably 264 -1
Result: the program compiled but it entered an infinite loop when I ran it!! I had to abort it manually. Do you have an explanation for this? |
|
|
int
to size_t
are in lines 29, 31 and 37
.
TheIdeasMan wrote: |
---|
When the for loop starts, it's initial j value is 0, but the increment is --j, so it tries to go negative straight away, but std::size_t is unsigned. Maybe that is a logical error you have there? Line 38 attempts to access A[j] and A[j+1]. If the loop is decrementing, I might have expected to start at the end of the array and work down, so maybe max_length should be the size of the vector A? |
std::size_t
to an int
If it's large enough, just don't compare them.