Pelles C forum

C language => Beginner questions => Topic started by: Gary Willoughby on January 02, 2010, 03:58:56 PM

Title: How do i fix 'warning #2030: '=' used in a conditional expression.'
Post by: Gary Willoughby on January 02, 2010, 03:58:56 PM
Why do i still get a:

warning #2030: '=' used in a conditional expression.

even when i'm surrounding the assignment in the while test with parenthesis?


#include <stdio.h>
#include <stdarg.h>

int Sum(int a, int b, ...)
{
   int arg;
   int Sum = a + b;

   va_list ap;
   va_start(ap, b);

   while((arg = va_arg(ap, int)))
   {
       Sum += arg;
   }
   va_end(ap);

   return Sum;
}

int main(int argc, char *argv[])
{
   printf("%d\n", Sum(1, 2, 4, 8));

   return 0;
}
Title: Re: How do i fix 'warning #2030: '=' used in a conditional expression.'
Post by: TimoVJL on January 02, 2010, 04:16:52 PM
...
while((arg = va_arg(ap, int)) != 0)
...
Title: Re: How do i fix 'warning #2030: '=' used in a conditional expression.'
Post by: Gary Willoughby on January 02, 2010, 04:47:01 PM
Great thanks.