This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: On alignment


Tom Tromey <tromey@redhat.com> writes:

[...]

| What will eventually go wrong with what we have now?
| 
|     template<typename T>
|     struct aligner
|     {
|       T field;
|     };
| 
|     #define ALIGNOF(TYPE) (__alignof__ (((aligner<TYPE> *) 0)->field))

This, as I understand it from my previous attempt, won't give you the
right answer (for double, it would give 8 instead of 4).

What is wrong with the following code I posted earlier?

    template<typename T>
      struct alignment {

         struct helper {
            T datum;
            helper();
         };

         static helper instance;

         enum { value = __alignof__ (instance) };
      };

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]