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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:02:08+00:00 2026-06-12T16:02:08+00:00

Probably a naïve question – I used to program 20 years ago and haven’t

  • 0

Probably a naïve question – I used to program 20 years ago and haven’t coded much since. My memory of how the C preprocessor works has atrophied significantly since then…

I am writing a very simple C program and I am trying to declare a few static global arrays, but the size of the arrays would be dependent (on a non-trivial way) on a MODE variable. Something like the simplified example below.

Two quick points: I know I could just size the arrays according to the largest size needed by any MODE, but I don’t want to that because (unlike in the simplified example below) sometimes a handful of these dimensions are going to be extremely large while others are tiny.

Also, I want to use statically defined global arrays – rather than dynamically allocate them at runtime. I want the compiler to have the sizes at compile time.

//** Simplified example of what I'd like to do **//    
#define SIZE_LIST_1[5] = {2, 7, 23, 33, 12, 76}  // I don't think this is valid syntax 
#define SIZE_LIST_2[5] = {11, 65, 222, 112, 444}

#define MODE 4
#define S1 SIZE_LIST_1[MODE]
#define S2 SIZE_LIST_2[MODE] 

int a[S1], b[S2];
  • 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-12T16:02:09+00:00Added an answer on June 12, 2026 at 4:02 pm

    You need to define a bunch of helper macros first before you can do this in a simple way:

    #define CONCAT(A,B)         A ## B
    #define EXPAND_CONCAT(A,B)  CONCAT(A, B)
    
    #define ARGN(N, LIST)       EXPAND_CONCAT(ARG_, N) LIST
    #define ARG_0(A0, ...)      A0
    #define ARG_1(A0, A1, ...)  A1
    #define ARG_2(A0, A1, A2, ...)      A2
    #define ARG_3(A0, A1, A2, A3, ...)  A3
    #define ARG_4(A0, A1, A2, A3, A4, ...)      A4
    #define ARG_5(A0, A1, A2, A3, A4, A5, ...)  A5
    #define ARG_6(A0, A1, A2, A3, A4, A5, A6, ...)      A6
    #define ARG_7(A0, A1, A2, A3, A4, A5, A6, A7, ...)  A7
    #define ARG_8(A0, A1, A2, A3, A4, A5, A6, A7, A8, ...)      A8
    #define ARG_9(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, ...)  A9
    #define ARG_10(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, ...)    A10
    
    /* above should be in a pp_helper.h header file or some such */
    
    #define SIZE_LIST_1 ( 2,  7,  23,  33,  12,   76)
    #define SIZE_LIST_2 (11, 65, 222, 112, 444, 1000)
    
    #define S1 ARGN(MODE, SIZE_LIST_1)
    #define S2 ARGN(MODE, SIZE_LIST_2)
    
    #define MODE 4
    
    int a[S1], b[S2];
    

    There are a bunch of preprocessor ‘libraries’ you can get with the boilerplate code (boost PP, P99), or you can just roll your own. The main problem being that you need to define ARG macros based on the largest number of arguments you’ll ever want to handle.

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

Sidebar

Related Questions

I don't know much about web development, so probably this question will sound exceptionally
I'm used to MSSQL, not Mysql, so sorry for this probably stupid question. I'm
Probably simple question but it has been a long time since i work with
Sorry for the probably stupid question. Since I found nothing about it on the
Since i'm not strong in asp.net, probably my question will sound silly. I've got
Pretty simple question (probably) but I guess since im new to python im not
This question probably is based on my lack of understanding of the role of
Simple (probably stupid) question. I'm a Powershell novice and am mainly using it to
i have another (probably unanswered) question about map views. I have a map view
Im sorry for this probably dumm question, but I want to simply open modals

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.