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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:17:39+00:00 2026-06-13T17:17:39+00:00

How can I extract [0…N] arguments from VA_ARGS assuming that N will be less

  • 0

How can I extract [0…N] arguments from VA_ARGS assuming that N will be less or equal to the number of arguments.

Example:

#define MY_SEQ r0, r1, r2,  r3,  r4,  r5,  r6,  r7, \
               r8, r9, r10, r11, r12, r13, r14, r15

#define EXTRACT_N(n, SEQ) {... magic ...}

...

EXTRACT_N(5, (MY_SEQ()));

should expand to:

{r0, r1, r2, r3, r4};

It’s ok to assume that sequence elements are of this form WHATEVER##N where N is Nth element.

I’m looking for some nice solution to this problem NOT using BOOST, e.g. I’d like to understand how it can be done.

I did it using iterative approach, but I’d like to know if there is some other way to do it.
Here’s how I implemented it:

#define EXTRACT_1(t0)               t0
#define EXTRACT_2(t0, t1)           EXTRACT_1(t0),t1
#define EXTRACT_3(t0, t1, t2)       EXTRACT_2(t0, t1),t2
#define EXTRACT_4(t0, t1, t2, t3)   EXTRACT_3(t0, t1, t2),t3
...
  • 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-13T17:17:41+00:00Added an answer on June 13, 2026 at 5:17 pm

    You cannot do that in the general case. The c preprocessor is not that flexible.

    You might have something like

    #define EXTRACT_N(N,A) EXTRACTTHEM ## N(A)
    

    and have

    #define EXTRACTTHEM1(X, ...) X
    #define EXTRACTTHEM2(X,Y, ...) X,Y
    

    etc

    (it is easy to generate an arbitrary large, but bounded, set of such macros).

    There are more powerful processors than cpp, e.g. m4 or gpp

    You might consider instead generating your C or C++ code (using your own script, or some generator) and having your building system (e.g. Makefile) take care of generating the C code from something different.

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

Sidebar

Related Questions

I'm looking for a parser that can extract methods from a java class (static
how can extract all the words that start with a particular letter from wordnet.
Is there a library that can extract all text events from an <input type=text>
I need a library that can extract text from handwritten paper once I scan
Does anyone know of any software that can extract the $bitmap file from NTFS
I'd like to sort an array such that i can extract some users from
Are there any APIs that can extract moods from a string (for use in
Is there a function that can extract two or more columns from a coeftest
I'm searching for a library that can extract (at least) the following information from
I want to create a java application that can extract specific sized icon from

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.