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

  • Home
  • SEARCH
  • 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 7681803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:25:28+00:00 2026-05-31T18:25:28+00:00

I need to write a macro that operates on bitarray looking like this: array[0]

  • 0

I need to write a macro that operates on bitarray looking like this:

   array[0] = number of bits in bitarray (integer) 
   array[1..n] = bits

Macro must look like:

GetBit(pointer, index)
Macro *must* return 0,1 or call function similar to exit().

This is my (working) inline-function version of macro that I’m supposed to write:

static inline unsigned long GetBit(BitArray_t array, unsigned long index)
{
        if ((index) >= array[0])
                        exit(EXIT_FAILURE);
        else
                return (GetBit_wo_boundary_checks(array,index));
}

This is what I’ve got:

#define GetBit(array,index)\
                (((index) < array[0] || exit(EXIT_FAILURE)) ?\
                        GetBit_wo_boundary_checks(array,index) : 0)

My problem is that this has to do index boundary check (i < p[0]) and exit before it tries to access undefined memory with GetBit_wo_boundary_checks(p,i).

I thought that I could work around this by putting exit into short-circuit evaluated condition, but I get: “invalid use of void expression”.

Is there any way to make this expression macro transparently exit() when index is higher than maximum defined in array[0]?

  • 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-31T18:25:29+00:00Added an answer on May 31, 2026 at 6:25 pm

    One option would be to use the comma operator with your exit() call, like:

    (exit(EXIT_FAILURE), 0)
    

    It’s a little hack-ish, but this will make the expression return the value 0 and should satisfy the compiler.

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

Sidebar

Related Questions

I need to write a multi-line macro. I need this because I must have
I need to write a macro in VBA that will open every file in
I'm a limited user, and I need to write an Outlook macro that exposes
Let's say that for some reason you need to write a macro: MACRO(X,Y) .
I want to write a macro in C that accepts any number of parameters,
I need to write a macro that searches a specified column and counts all
I need to write, in JavaScript (I am using jQuery), a function that is
I need to write a small console app (patch) that turns off the print
I need to write an app that reads a config file with info on
I need to write a python script that makes multiple HTTP requests to the

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.