-2

Functions can return a number, pointer, and most of the type you want, but what's the meaning of it?

return ret < 0;

(This code snippet is from the last line of the code, ffprobe.c.)

haccks
  • 104,019
  • 25
  • 176
  • 264
Kevin Dong
  • 5,001
  • 9
  • 29
  • 62
  • 3
    What part of that do you not understand? Do you know the "return" keyword in C? Do you know the comparison operator `<`? Do you recognize `ret` as a variable declared earlier? Put it all together.... – abelenky Jan 07 '14 at 16:48

3 Answers3

14

It will return either 1 or 0 depending upon the condition ret < 0 is true or false.

You can understand this as

if(ret < 0)
    return 1;
else  
    return 0;
haccks
  • 104,019
  • 25
  • 176
  • 264
  • Aww edited to say half of what I said. At least it's more clear for the op. – uchuugaka Jan 07 '14 at 16:48
  • Before your answer I already had edited my answer but I became late because of my slow internet connection (Downloading a game *Injustice* :D) – haccks Jan 07 '14 at 16:54
  • Just a friendly jibe. Just happy it's clear. The kind of traditional C coding style is confusing for people new to it who've probably seem more explicit coding styles (in normal human reading terms) while the traditional C pedantic people would say it is explicit because they are used to reading code the hard way by order of evaluation. – uchuugaka Jan 08 '14 at 00:23
  • In other terms you can say: *Its a beauty of C* :) – haccks Jan 08 '14 at 02:52
2

It returns the value of the conditional operation. ret < 0 It's C shorthand that you often see. C programmers are notoriously pedantic and do not write code that is obvious to the learner. It's equivalent to what might be written explicitly for mortals as

if ( ret < 0 ) { return true; } else { return false; }

uchuugaka
  • 12,679
  • 6
  • 37
  • 55
1

return statement can have a expression. when a function is returning using a return statement it evaluates the expression first.

       return (expression);

expression can be any valid expression in C. after evaluation it returns whatever value is the output of the expression(assuming the return type matches or compiler will through an error ) in your case the statement will be like

      return (ret < 0);

depending on the value of ret either 1( if ret is less than 0) or 0(if ret is greater than 0) will be returned

KARTHIK BHAT
  • 1,410
  • 13
  • 23