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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:19:06+00:00 2026-05-23T11:19:06+00:00

How would I define multiple values of the same type in an array using

  • 0

How would I define multiple values of the same type in an array using #define ?

For instance, I would like

#define DIGIT 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39
#define QUOTE 0x22 | 0x27

ETC...
  • 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-23T11:19:06+00:00Added an answer on May 23, 2026 at 11:19 am

    How would I define multiple values of the same type in an array using #define ?
    For instance, I would like

    #define DIGIT 0x30 | 0x31 | 0x32 | 0x33 | 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39
    #define QUOTE 0x22 | 0x27
    

    Well, the term array in C and C++ refers to a number of variables of the same type, all side by side in memory. If you really wanted an array, then you can use:

    static const char digits[] = {
        0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
    };
    

    Of course, there’s nothing to stop you putting part of this in a preprocessor macro, but no obvious point either, and macros are best avoided as conflicting and unintended substitutions aren’t always handled well by the compiler:

    #define DIGITS 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
    static const char digits[] = { DIGITS };
    

    If your intension it to check whether a particular character is one of the listed characters, then you can do it in many ways:

    if (isdigit(c)) ...    // use a library function
    
    static const char digits[] = {
        0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0
    };
    if (strchr(digits, c)) ...  // use another library function (probably slower)
    
    static const char digits[] = "0123456789";  // exactly the same as above!
    if (strchr(digits, c)) ...
    
    if (c == 0x30 || c == 0x31 || c == 0x32 ...) ...    // painfully verbose!
    
    if (c == '0' || c == '1' || c == '2' ...) ... // verbose but self-documenting
    
    if (c >= '0' && c <= '9')  // as per caf's comment, C requires the
                               // character set to have contiguous numbers
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to define multiple modules in the same file. I would like to
I'm using Phil Haack's URL routing for WebForms and I would like to define
I would like to define a constant (like the admin-email-adress) depending on the environment.
I would like to define and initialize some variables in web.xml and the access
I would like to define some kind of safe division (and modulo) function, one
I would like to define the z order of the views of a RelativeLayout
How would I return multiple values (say, a number and a string) from a
Using IBM Informix Dynamic Server Version 10.00.FC9 I'm looking to set multiple field values
How would you define testing? In the interest of full disclosure, I'm posting this
How would I define an element that can either contain plain text or contain

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.