public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Gonzalez, Inaky" <inaky.gonzalez@intel.com>
To: "'Andrea 'Fyre Wyzard' Bocci'" <fwyzard@inwind.it>, gcc-help@gcc.gnu.org
Subject: RE: Differences in struct size when compiling C vs. C++
Date: Tue, 22 Jan 2002 12:20:00 -0000	[thread overview]
Message-ID: <13FCCC1F3509D411B1C700A0C969DEBB05E20D01@fmsmsx91.fm.intel.com> (raw)



> I think this is the same as in issue discussed a month ago on 
> the gcc ML 
> for classes (http://gcc.gnu.org/ml/gcc/2001-12/msg00836.html).
> Shortly:
> The empty struct sub-object must have a different address 
> from the struct 
> that contains it.
> This is obvious with A, where "int d" between the two makes 
> this happen 
> automatically.
> With B, the compiler must use an empty byte to let the struct 
> {} c addres 
> be different from that of B.

	Do you know if there is anyway then to do it? I have this data type,
and I template it:

template<class T>
struct A
{
  int a;
  int b;
  T c;
};

The idea is T is normally a class that offers an interface like:

struct T1
{
  void fn1 (void);
  void fn2 (void);
 private:
  // data members
};

And sometimes it is like:

struct T2
{
  static void fn1 (void);
  static void fn2 (void);
  // no data members, stateless
}

So, I want struct A<T> to be minimal size (8 bytes) when I am using T2 [as
it in theory should be] and to be whatever it has to be if it is T1. Note
there is no runtime discovery of types implied here, as it is all know at
compile time (love templates :).

I would expect that being that empty struct, it'd be optimized out by the
compiler, so I can use the same interface w/o the size penalty, but looks
like GCC thinks differently. Maybe there is a way to trick it ...


Iñaky Pérez González -- (503) 677 6807
I do not speak for Intel Corp, opinions are my own.

             reply	other threads:[~2002-01-22 20:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-22 12:20 Gonzalez, Inaky [this message]
     [not found] <13FCCC1F3509D411B1C700A0C969DEBB05E20D01@fmsmsx91.fm.intel .com>
2002-01-22 13:09 ` Andrea 'Fyre Wyzard' Bocci
  -- strict thread matches above, loose matches on Subject: below --
2002-01-16 20:14 inaky.gonzalez
2002-01-17  4:20 ` Andrea 'Fyre Wyzard' Bocci

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=13FCCC1F3509D411B1C700A0C969DEBB05E20D01@fmsmsx91.fm.intel.com \
    --to=inaky.gonzalez@intel.com \
    --cc=fwyzard@inwind.it \
    --cc=gcc-help@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).