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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:33:05+00:00 2026-06-12T09:33:05+00:00

Alright, I’m pretty sure that this has been discussed before in some way or

  • 0

Alright, I’m pretty sure that this has been discussed before in some way or another, but I’m apparently too stupid to find it.

First: I’m NOT looking for va_list and the other macros.
What I am looking for is something like the main-function parameters.

The default prototype, as all of you know is:

int main(int argc, char *argv[]);

Now, I want something similar for my program, but don’t know how exactly.

Let’s assume we have this function:

void Function(int argc, unsigned short *args[]) {
    for(int i = 0; i < argc; ++i) printf("%hu ", args[i]);
}

And I want something like this function call:

Function(5, 1, 2, 3, 4, 5);

Would that work?
Because I don’t want the ‘cluttering’ of va_list, nor do I want to create:

void AnotherFunction() {
    unsigned short Args[] = { 1, 2, 3, 4, 5 };
    Function(5, Args);
}

Simply because in that case I would only need a simple pointer.
Could someone please point me in the right direction? Thank you very much.

Edit:
Thank you everyone for your valuable input. I’ll settle for ‘Doesn’t work with standard C/C++ for now and look for a different approach to my problem.

Again, thank you very much.

  • 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-12T09:33:06+00:00Added an answer on June 12, 2026 at 9:33 am

    A g++ specific solution:

    const size_t MAX_ARGS = 42;
    
    void Function(int argc, const unsigned short (&args)[MAX_ARGS])
    {
    }
    
    int main()
    {
        Function(5, {1,2,3,4,5});
    }
    

    If you don’t actually need the argc parameter, you can write a template:

    template<size_t N>
    void Function(const unsigned short(&args)[N])
    {
        // use N
    }
    

    This works in C++03. The array needs to be const, or else you can’t pass a temporary initializer list like that. If you need to modify the elements inside the function, you’ll need to make a copy.

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

Sidebar

Related Questions

Alright, I understand that this problem has been asked a lot of times at
Alright, so I'm about 90% sure that this isn't possible, but I thought I'd
Alright. This may be difficult but I have been struggling for quite a bit
Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright, this is driving me nuts because my regex is working on Rubular, but
Alright so I have no idea how to even begin doing this But basically
Alright I created some custom classes for my project sourced from this tutorial ,
Alright so this is a bizarre cross platform thing that I'm experiencing with text
Alright, so I'm new to Android programming, so far my experience has been quite
Alright, so I've been trying to implement a simple binary search tree that uses

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.