How do I Suppress a Warning in Xcode?

I have a function that computes a power of -1:
1
2
3
4
int negOneToTheXthPower (long x) {
	if (x % 2 == 0) return 1 ;
	else if (x % 2 == 1) return -1 ;
	}


Building this gives me a
Control reaches end of non-void function
warning (apparently control is not odd or even :P ) . How do I suppress this warning? I found out about #pragma GCC diagnostic ignored "-Wwarningflag" but I don't know what warningflag would be in this case, and I don't know where to look (Google wasn't helpful) .
the easy solution is to just get rid of your redundant condition:

1
2
3
4
5
6
7
int negOneToTheXthPower (long x)
{
  if (x % 2 == 0)
    return 1 ;
  else // no if() here
    return -1 ;
}



Not only is this less code for you to type, but it's also possibly faster since the additional check can be omitted, and it reduces duplicate code (duplicate code = evil)
Last edited on
Topic archived. No new replies allowed.