Mailinglist Archive: opensuse-buildservice (233 mails)

< Previous Next >
Re: [opensuse-buildservice] Re: no-return-in-nonvoid-function not always true
  • From: Werner Hoch <werner.ho@xxxxxx>
  • Date: Thu, 18 Dec 2008 11:51:56 +0100
  • Message-id: <200812181151.56829.werner.ho@xxxxxx>
On Donnerstag, 18. Dezember 2008, Bernhard Walle wrote:
* Werner Hoch [2008-12-18 08:25]:
Bernhard Walle suggest to make that errors ignorable.

That was a different story. In you case the code is just wrong.
Nobody can guarantee that you call the function with !(i == 1 || i ==
2).

Sorry for my poor example, here's a better one where I can guarantee
that it's ok.

----------------
#include <stdio.h>

int testfunc(unsigned int i)
{
switch (i%2) {
case 0: return 2;
case 1: return 5;
}
}

int main(void)
{
printf("%d, %d\n", 5, testfunc(5));
printf("%d, %d\n", 4, testfunc(4));

return 0;
}
----------------

compiler output:
--------
werner@linux-m82i:~/puffer> gcc -Wall main.c
main.c: In function ‘testfunc’:
main.c:11: warning: control reaches end of non-void function
werner@linux-m82i:~/puffer> ./a.out
5, 5
4, 2
werner@linux-m82i:~/puffer>
-------

I know that a default statement could fix the compiler warning.
----------
switch (i%2) {
case 0: return 2;
case 1: return 5;
default: /* never reached */
return 5;
}
----------

I'd just prefer to disable the check in such cases without patching all
the code.

Regards
Werner
--
To unsubscribe, e-mail: opensuse-buildservice+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse-buildservice+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups