Serial.print strangeness

I'm getting one of those bugs which is making my head hurt.

When I use this code:

  while (true)
      {
        //Serial.print(get_light_level(pin,BASE_LIGHT_LEVEL));
        
        get_light_level(pin,BASE_LIGHT_LEVEL);
        
        
        delay (UNIT_TIME_MS);
   
      }

bool get_light_level (byte pin,int BASE_LIGHT_LEVEL)
{
  if (BASE_LIGHT_LEVEL - analogRead(pin) > LIGHT_SENSITIVITY)
  {
    Serial.print("1");
    return true;
  }
  
  else
  {
    Serial.print("0");

    return false;
  } 
  
}

the output is correct.

However, when I print in the calling function:

      while (true)
      {
        Serial.print(get_light_level(pin,BASE_LIGHT_LEVEL));
        
        //get_light_level(pin,BASE_LIGHT_LEVEL);
        
        
        delay (UNIT_TIME_MS);
   
      }

bool get_light_level (byte pin,int BASE_LIGHT_LEVEL)
{
  if (BASE_LIGHT_LEVEL - analogRead(pin) > LIGHT_SENSITIVITY)
  {
   // Serial.print("1");
    return true;
  }
  
  else
  {
    //Serial.print("0");

    return false;
  } 
  
}

the output is incorrect.

My application is fairly time sensitive but I can't think why I'm getting different results (the above results are completely consistent).

Any ideas?

Because you are printing a "bool" variable and inside the function you are printing something too.

luisilva: Because you are printing a "bool" variable and inside the function you are printing something too.

True but that doesn't explain the different results.

sbaratheon: True but that doesn't explain the different results.

What are these results you speak of? Care to share what the output was that confused you?

sbaratheon: True but that doesn't explain the different results.

Yes it does! It's only a matter of know what do you mean you with strange. If you don't mind of explain what you are getting maybe someone can help you.

BTW, what about:

      while (true)
      {
        if (get_light_level(pin,BASE_LIGHT_LEVEL) == true) {
        
           Serial.print("1");
        }
        else {
           Serial.print("0");
        }
        delay (UNIT_TIME_MS);
   
      }

bool get_light_level (byte pin,int BASE_LIGHT_LEVEL)
{
  if (BASE_LIGHT_LEVEL - analogRead(pin) > LIGHT_SENSITIVITY)
  {
    return true;
  }

  else
  {
    return false;
  }

what is the result that gives you?