In this case, I'd go for the solution:
int sign(int i)
{
if (i > 0)
return 1;
else if (i == 0)
return 0;
else
return -1; // i<0
}
That is, I would add two else clauses - to make the code more symmetric, rather than because it makes any difference to the object code generated.
I did some experimentation. I expected the one-line version using the the ternary operator twice to generate the same code as the longer. However, testing on Solaris 10 (SPARC) with GCC v4.3.2 shows that the ternary operator version is consistently 12-16 bytes smaller than the 'if' version. However, the presence or absence of the extra else does make no difference. (Adding register made no odds, as I'd expect.) Added I also looked at Christoph's solution with 'return (i > 0) - (i < 0);' - a variant I'd not seen before. The code sizes were:
Unoptimized Optimized (-O5)
if 166 110
?: 150 98
>-< 122 98
Which mostly goes to show that measurement is a good idea!