public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Byron Stanoszek <gandalf@winds.org>
To: gcc@gcc.gnu.org
Subject: Feature-request: Possibility of transparent unions in structs
Date: Fri, 24 Mar 2000 20:08:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.21.0003242307500.16140-100000@winds.org> (raw)

I have a large piece of code that uses the members of certain structures
conditionally depending on other members of the structure. Furthermore, since
only some of the members of the struct are used at some times, I feel I could
save memory by making those members into a union. The problem is, I don't want
to change those struct members in 60,000 lines of code.

The question: Is there a way to make the union identifier transparent to the
structure, such that the members of the union can be referenced from the
context of the structure?

Example:

Changing the original structure:

struct foo {
  int type;    // Type= 0:use id, 1=use data, 2=use string
  int id;
  int *data;
  char *string;
};

to this to decrease size of structure in memory:

struct foo {
  int type;
  union ident {
    int id;
    int *data;
    char *string;
  };
};

BUT with the ability to retain the original calling method from a function:

void bar() {
  struct foo *ptr;

  switch(ptr->type)
  {
    case 0:
      id_function(ptr->id);
      break;
    case 1:
      data_function(ptr->data);
      break;
    case 2:
      string_function(ptr->string);
      break;
  }
}

I looked up the info files and found something close-- transparent_union
attribute, but it (assumingly) only works with function calls and not from
within a structure, as per documentation states. What I'd really like to do is
limit my memory usage without having to rename each portion of code to
something that looks like ptr->ident.id, etc.

Can anyone tell me if this feature exists currently in GCC (as a C extension),
or if possible, can be added to gcc 2.96 / 3.0?

Thank you!

	-- Byron Stanoszek <gandalf@winds.org>


             reply	other threads:[~2000-03-24 20:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-24 20:08 Byron Stanoszek [this message]
2000-03-25  9:12 ` Mumit Khan
2000-03-27  9:36 ` Joe Buck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.21.0003242307500.16140-100000@winds.org \
    --to=gandalf@winds.org \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).