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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:00:26+00:00 2026-06-06T03:00:26+00:00

Here is a structure used in a program: struct basic_block { void * aux;

  • 0

Here is a structure used in a program:

struct basic_block
{
  void * aux;

  /* Many other fields,
  which are irrelevant.  */
};

Now:

  1. Several instances of basic_block exist during the execution of the program.
  2. The program works in stages/passes, which are executed one after another.
  3. The aux field is meant for storing stage and basic_block specific data during the execution of a stage, and freed by the stage itself (so the next stage can reuse it). This is why it is a void *.

My stage uses aux to store a struct, so each time I want to access something, I have to do a cast:

( (struct a_long_struct_name *) (bb->aux))->foo_field = foo;

Now, my problem: Casting it each time like this is a pain, and difficult to read when it is part of more complicated expressions. My proposed solution was: Use a macro to do the cast for me:

#define MY_DATA(bb) \
  ( (struct a_long_struct_name *) (bb)->aux)

Then I can access my data with:

MY_DATA(bb)->foo_field = foo;

But: I cannot use MY_DATA(bb) itself as an L-value (for a malloc), so I using that macro isn’t such a good idea after all:

/* WRONG! I cannot assign to the result of a cast:  */
MY_DATA(bb) = malloc (sizeof (struct a_long_struct_name));

My question:

What can I do in order to refer to aux in a clean way and still be able to use it as an L-value.

  • 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-06T03:00:30+00:00Added an answer on June 6, 2026 at 3:00 am

    You can cast the address of the field to struct a_long_struct_name ** and then dereference it:

    #define MY_DATA(bb) \
       (* ((struct a_long_struct_name **) &(bb)->aux) )
    

    This will work in both the constructs you have shown.

    If the set of possibilities for the concrete type of aux can be known at the point where struct basic_block is declared, though, it would be cleaner to use a union:

    struct basic_block
    {
      union {
          struct a_long_struct_name *alsn;
          /* etc */
      } aux;
    
      /* Many other fields,
         which are irrelevant.  */
    };
    

    and then

    #define MY_DATA(bb) ((bb)->aux.alsn)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so here's the situation: suppose I have a class structure used to represent flexible
For example I have a file name call A.java. Here its structure: public class
okey so here is my structure. one.php two.php three.php one.php includes both two.php and
I have a document structure {'text': 'here is text', 'count' : 13, 'somefield': value}
I have a complex form in Ruby on Rails 2.3.5, here's the structure for
Here is the simplified table structure of PRICES : SKU PriceType FromDate ToDate Price
Here's the XAML structure. You'll see below that I'm subscribing to the Loaded event
Here is a table structure (e.g. test): Field Name Data Type id BIGINT (20)
Here is my data structure alt text http://luvboy.co.cc/images/db.JPG when i try this sql select
Here is my project structure: /app --/lib ----/porter.rb --/spec ----/porter_spec.rb In file porter_spec.rb i

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.