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

  • Home
  • SEARCH
  • 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 8604039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:28:14+00:00 2026-06-12T02:28:14+00:00

I referred this SO Answer for creating variadic function in objective C. I tested

  • 0

I referred this SO Answer for creating variadic function in objective C.
I tested your code by passing arguments like below:

[self logMessage:@"string: %@\n number: %@\n image: %@",
 @"asdf",
 [NSNumber numberWithInt:23],
 [UIImage imageNamed:@"local.png"]];

and edited the code with NSLog();

- (void)logMessage:(NSString *)format, ... {

    va_list args;
    va_start(args, format);

    id arg = nil;
    int i = 1;
    NSLogv(format, args);
    while ((arg = va_arg(args,NSString *))) {

        NSLog(@"val: %d", i++);
        /// Do your thing with arg here
        //NSString *name = NSStringFromClass([arg class]);
        //NSLog(@"string: %@", name);
    }        
    va_end(args);
}

But the output as follows:

2012-09-28 19:34:45.271 SIMO[2384:c07] string: asdf
 number: 23
 image: <UIImage: 0x8151f80>
2012-09-28 19:34:45.273 SIMO[2384:c07] val: 1
2012-09-28 19:34:45.273 SIMO[2384:c07] val: 2
2012-09-28 19:34:45.274 SIMO[2384:c07] val: 3
2012-09-28 19:34:45.274 SIMO[2384:c07] val: 4
2012-09-28 19:34:45.274 SIMO[2384:c07] val: 5
2012-09-28 19:34:45.275 SIMO[2384:c07] val: 6
2012-09-28 19:34:45.275 SIMO[2384:c07] val: 7
2012-09-28 19:34:45.276 SIMO[2384:c07] val: 8

This tells that the argument is 8, but I passed only 3 (NSString, NSNumber, UIImage)
I can’t get the concept.. Could you clarify me
Could anyone clarify this

  • 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-06-12T02:28:15+00:00Added an answer on June 12, 2026 at 2:28 am

    va_arg doesn’t really know when the argument list ends. The approach you’re using expects the argument list to be terminated by nil, like +[NSArray arrayWithObjects:].

    So either change your invocation to add nil at the end of the argument list, or find some other way of knowing when the arguments are over (e.g. for a printf clone, you might know the number of format arguments from the format string itself).

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

Sidebar

Related Questions

I have referred this for creating error message tool tips, to be displayed continuously
From this answer in stack overflow and the sample project referred there, i got
While finding answer for this query with writing test code, I got to know
I referred this on SO as the problem was similar to mine. In my
I have developed a resizable panel in GWT. For this i have referred the
In the following code upto what scope the anonymous array referred by $ref is
This may look like the recent question that asked why Perl doesn't allow one-liners
In the answer to this question on the kiln stack exchange site, there is
This anwser suggest send 'no-cache' HTTP headers back with your response from the server.
I have referred all question of stackoverflow but i don't found exact answer of

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.