Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 518885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:59:00+00:00 2026-05-13T07:59:00+00:00

In the following C program i get the warning: warning #2030: ‘=’ used in

  • 0

In the following C program i get the warning:

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

What exactly is the problem and how do i avoid this? What is the correct way to iterate through the variable arguments?

#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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:59:00+00:00Added an answer on May 13, 2026 at 7:59 am

    What you’re doing is idiomatic, if slightly ugly C.

    In order to convince the compiler you know what you’re doing, though, you could wrap the assignment into an additional set of parentheses:

    while((arg = va_arg(ap, int)))
    

    That should take care of the warning.

    Update:

    adding parenthesis around the assignment doesn’t seem to supress the warning in the C99 compiler im using (PellesC). – Gary Willoughby

    What, it didn’t? Then you need to make the test a little more explicit:

    while((arg = va_arg(ap, int)) != 0)
    

    should do the trick. It could also be argued to be slightly more readable.


    You’re going to ask me what I mean by “slightly ugly.”

    From working with other languages, I’m used to having a clear separation between testing and modifying. You’re doing a test in that while of a value, but at the same time creating a side effect (namely reading in the next argument). As I said, this is considered pretty normal, yea “idiomatic” in C because a lot of C programmers do this; I think there are even examples of similar code in K&R.

    By personal preference, I’d probably rewrite this as:

    while (1) {
      arg = va_arg(ap, int);
      if (!arg) break;
      ...
    }
    

    This clearly separates the assignment from the test, and lets the loop stand alone as a (potentially) infinite loop. Many people would consider my code more ugly; as I said, it’s a matter of personal preference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my simple OpenGL program I get the following error about exit redefinition: 1>c:\program
I wanted to use boost::thread in my program, but get the following compiler error
Why does the following program give a warning? Note : Its obvious that sending
I'm getting the following error Program received signal: EXC_BAD_ACCESS. warning: check_safe_call: could not restore
I get the following as a warning during build of my asp.net application: The
The following program is very simple: it outputs a single dot each half a
I have the following program: ~/test> cat test.cc int main() { int i =
Suppose I've got the following program: namespace ReflectionTest { public class Example { private
let us have a situation in which the following program prints some 10 lines
Hey everyone, I am trying to run the following program, but am getting a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.