For the gurus of C++

Hi everyone,

I started playing with c++ in Arduino a I am enjoying it a lot!
I've read plenty of foruns and literature, but I really can't figure this one out.

I have two equal objects, but when submitted to the same test, they present different outputs.

On the left you have the code of the function, and on the right, the output. I have placed a few prints to debug it...
But, why oh why the function does not enter in the loop!??!?!?!?

Thanks

void database_float_sheet::print_sheet (Serial_ &print) {
  int i, k, l;
  float a;
  char aux[50];
  k=1;
    sprintf(aux,"%i   %i   %i\n",first, (first+i*size_entry), first_available);
    print.write(aux);
  for (i=(int) first; (int)(first+i*size_entry) < (int)first_available; i++) {
    print.write("eeeeeeee\n");
    delay(100);
    ftoa(aux, read(i), 2);
    print.write(aux); 
    print.write("; ");
    if (k == 10) {
      print.write("\n");
      k=0;      
    }
    k++;
  }
  print.write("Done\n");
}

The output is:

T
0 0 40
eeeeeeee
24.51; eeeeeeee
24.51; eeeeeeee
24.51; eeeeeeee
24.51; eeeeeeee
24.51; eeeeeeee
24.51; eeeeeeee
24.51; eeeeeeee
24.51; eeeeeeee
24.51; eeeeeeee
24.51;
Done

V
40 40 80
Done

Please post your code

filipe22:
Hi everyone,

I started playing with c++ in Arduino a I am enjoying it a lot!
I've read plenty of foruns and literature, but I really can't figure this one out.

I have two equal objects, but when submitted to the same test, they present different outputs.

On the left you have the code of the function, and on the right, the output. I have placed a few prints to debug it...
But, why oh why the function does not enter in the loop!??!?!?!?

Thanks

Describe the problem accurately, and post your code between code tags. ( </> in the reply window. )
As Bob has just pointed out as well.
Place your output in code tags too.

N.B. There's nothing on either the left or right at the moment.

Code uploaded!

We love guessing games.

When we say "post your code", we really mean it.

== does not compare the objects, normally it will just compare the addresses of the instances of the objects.

That is unless == has been overloaded!

Mark

    sprintf(aux,"%i   %i   %i\n",first,

This implies that first is an int.

  for (i=(int) first; (int)(first+i*size_entry) < (int)first_available; i++) {

You really look like an idiot, casting an int to an int.

filipe22:
But, why oh why the function does not enter in the loop!??!?!?!?

sprintf(aux,"%i   %i   %i\n",first, (first+i*size_entry), first_available);

Here, i = zero (altho you haven't initialized it),
so first + i * size_entry is the same as first.

for (i=(int) first; (int)(first+i*size_entry) < (int)first_available; i++) {

Here, when you evaluate the condition, you have already assigned a new value to i: first.
So now, first + i * size_entry is potentially greater than first_available,
and then the condition would never be true.

Thank you Jobi-Wan!

Really appreciate your help!
Solved it

PaulS:
You really look like an idiot, casting an int to an int.

The insult seems unnecessary and unprovoked. Bad day?