Mailinglist Archive: opensuse-programming (62 mails)

< Previous Next >
unsigned ints as parameter to function
  • From: Brad Bourn <brad@xxxxxxxxxxxx>
  • Date: Fri, 11 Feb 2005 10:44:20 -0700
  • Message-id: <200502111044.20423.brad@xxxxxxxxxxxx>
I have a function say like this

func(unsigned int foo)
{
unsigned int i, retval = 0;
for (i = 0; i < foo; i++)
{
retval++;
}

return retval;
}

and I call it with

val = func(4 - 3);


Seems like gcc WILL pass the -1 to func, and func just get stuck in a loop
becase i starts at 0 (which is alread greater than a negative number)

This not what I would have expected.

Is this by design?

< Previous Next >