possible bug in g++ variable alignment

Ron Kaminsky kam@orbotech.com
Mon Feb 28 14:33:00 GMT 2005

When compiling (using "g++") and running the following program:

/* start program example */
#include <iostream>

unsigned char t[1] __attribute__((aligned(16)));

using namespace std;

int main()
   static unsigned char s[1] __attribute__((aligned(16))) ;

   cout << "s = " << ((int) &s[0]) % 16 << endl;

   return 0;
/* end program example */

I get the result:

s = 8

when I would expect (as I get under Linux)

s = 0

I know that "g++" is dependent on "ld" which limits its maximum
alignment, but under Cygwin, it/they only print/s warnings for
alignments which are > 16.

Note that all is OK if you don't try to also align the global
variable "t".

Also note that if "s" is not declared "static", this doesn't even
work under Linux for me (perhaps with a slightly changed program,
with larger alignment moduli). However, I see no documentation
that automatic variables cannot be aligned using this construct.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygcheck.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20050228/1cb67344/attachment.ksh>
-------------- next part --------------
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

More information about the Cygwin mailing list