This is the mail archive of the gcc-bugs@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: libstdc++/6732: misaligned objects created by new


Synopsis: misaligned objects created by new

State-Changed-From-To: open->analyzed
State-Changed-By: bkoz
State-Changed-When: Wed Jul  3 22:51:48 2002
State-Changed-Why:
    I'm not quite convinced that this is a C++ library problem.
    It seems like "C" also has the same issue. 
    
    Note that gcc-2.96, others also have the same behavior.
    
    
    #include <iostream>
     
    struct vec4 
    {
      float x, y, z, w;
    } __attribute__((__aligned__(16)));
    
    int main()
    {
      std::allocator<vec4> a;
      
      for (int i = 0; i < 10; ++i) 
        {
          vec4* p = new vec4;
          std::cerr << reinterpret_cast<void*>(p) << " ";
          std::cerr << reinterpret_cast<std::size_t>(p) % 16 << " ";
          std::cerr << std::endl;
        }
    
      for (int i = 0; i < 10; ++i) 
        {
          vec4* p = reinterpret_cast<vec4*>(malloc(sizeof(vec4)));
          std::cerr << reinterpret_cast<void*>(p) << " ";
          std::cerr << reinterpret_cast<std::size_t>(p) % 16 << " ";
          std::cerr << std::endl;
        }
    }
    

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6732


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