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 3333482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:48:05+00:00 2026-05-17T23:48:05+00:00

In Objective-C you can say something like: NSArray *anArray = [NSArray arrayWithObjects:obj,obj2, nil]; In

  • 0

In Objective-C you can say something like:

NSArray *anArray = [NSArray arrayWithObjects:obj,obj2, nil];

In case you are not familiar with objective-c it is saying I want an object of type of NSArray, anArray, and I want to call the method arrayWithObjects and then it acts as a sentinel and accepts as many parameters (which in this case are objects) until it reaches nil.

Is there any way to achieve something like this:

createObjects(o1,o2,o3,o4,-1);

Where the method of function can accept as many parameters until it reaches some key value?

Now, I am aware you can do sentinel stuff in C and C++, but is there a way to provide something like this to a method like they do in Objective-C?

  • 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-17T23:48:06+00:00Added an answer on May 17, 2026 at 11:48 pm

    You can write a variadic function and use a sentinel to locate the last real argument.

    However, in C++, this is usually a bad idea because variadic functions are not type safe. It’s preferred in C++ to put the elements you want to pass into a container, array, or class object of some kind and then pass that to the function. It’s much less error-prone and much easier to verify.

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

Sidebar

Related Questions

In the Modern Objective-C runtime, you can do something like this: @interface MyClass :
I heard that calling a handler (delegate, etc.) in Objective-C can be even faster
Can a Objective c interface have more than one implementation? Example I could have
In objective-c I can do the following: NSTask* foo = [NSTask alloc]init]; [foo setLaunchPath:@/usr/bin/open];
I currently have code in objective C that can pull out an integer's most
As I understand, in Objective-C you can only put Objects into dictionaries. So if
I can do this in Objective-C on the iPhone, but now I'm looking for
I can only find asynchronous iPad/objective C HTTP examples. How do I do a
How can I invoke a method at runtime on an Objective-C class when all
I can't seem to find any documentation on the Objective-J language itself. Does it

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.