Nathan Sidwell nathan@acm.org
Tue Sep 8 13:05:00 GMT 1998

What is a desirable value for __alignof__(void) to return? Documentation
does not comment. Currently it returns 1, and the gcc's source code
treats it the same as an ERROR_MARK node.

IMHO a useful value to return would be the maximum alignment for any
type. I can't see a use for the current behaviour, but I can (and do)
have a use for the suggested behaviour. By default, gcc treats
sizeof(void) as 1, and allows void pointer arithmetic, I don't think
there's a pressing reason for alignof to do the same.

I have added just this behaviour in both gcc and g++, but as this is
changing the behaviour of gcc/g++ in a visible manner, I am holding off
submitting it, while waiting for feedback.

Here's an example C++ program who's behaviour would be altered.
#include <stdio.h>

template<class T> unsigned fn(){return __alignof__(T);};

int main()
  printf("char %d int %d void %d\n",
      __alignof__(char), __alignof__(int), __alignof__(void));
  printf("char %d int %d void %d\n",
      fn<char>(), fn<int>(), fn<void>());
  return 0;

on my sparc box, the output curently is
	char 1 int 4 void 1
	char 1 int 4 void 1
but would change to
	char 1 int 4 void 8
	char 1 int 4 void 8


Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk

More information about the Gcc mailing list