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]

What should alignof do with incomplete types?


Given the program:

struct a { int c; int d; };
struct b;

main()
{
  printf("Alignment of a is %d\n", __alignof__(struct a));
  printf("Alignment of b is %d\n", __alignof__(struct b));
}

GCC (2.90) results in:

Alignment of a is 4
Alignment of b is 0

Apple's version of GCC warns about struct b, and reports
1 instead of 0, so as avoid possible divides by zero:

% cc a.c
a.c: In function `main':
a.c:8: warning: __alignof applied to an incomplete type
% ./a.out
Alignment of a is 4
Alignment of b is 1
% 

The change is very simple, but it occurs to me that the current
behavior might be deliberate, although it's not specified either way
in the manual.  On the other hand, one could make the case that alignof
on an incomplete type should be an error rather than just a warning,
since it's hard to imagine how this could be legitimate code, and
since the compiler is unlikely to be able to guess at a correct value.
 
In any case, before preparing a patch, I'd like to know whether the
current behavior is considered to be a problem.

Stan

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