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]

small patch to c-pragma.c


Hello,

I have a very small patch to egcs-1.1.2

Basically, I just want to add a case statement to c-pragma to handle

#pragma pack(8) 

for 64 bit architectures.

I have read the dogma about how terrible it is to use #pragma pack(),
but our code has it all over the place and we can't really see a
feasable alternative.  We pass over 100 different structures around in 
network packets and binary databases and have to work in a
mixed-endien environment.


*** ./c-pragma.c.dist	Thu May 28 02:47:21 1998
--- ./c-pragma.c	Fri Jun 18 10:11:13 1999
***************
*** 143,148 ****
--- 143,149 ----
  	  case 1:
  	  case 2:
  	  case 4:
+ 	  case 8:
  	    align = TREE_INT_CST_LOW (token);
  	    state = ps_align;
  	    break;


Even if you don't add this change, let me say, "Thanks", because 
fixing this in egcs  is easier to patch than gcc 2.7.2!

You have to be working on an environmnet where -DSVR4 (and by
inference -DHANDLE_SYSV_PRAGMA) is defined.  (Unixware, Solaris,
NCR,...)  I have gone in on the other archtiectures we use like Linux
and Digital Unix and just added -DHANDLE_SYSV_PRAGMA into the specific 
.h file for that architeture.  I don't suppose there is a chance that
this feature would be enabled by default on all architectures?

I have a little test program that exercises the code below. It gives a 
bus error on solaris, but it is something kind of obscure than can be
worked around by using 'memcpy' instead of a direct assignment.

Thanks,
-Eric.

------------------------------------------------------------------------------

#include <stdio.h>
#include <stddef.h>
struct foo
{
	int a;
	char b;
	void * c;

};

#pragma pack(1)

struct bar
{
	int a;
	char b;
	void * c;
	struct foo d;
	int e;
};

/*#pragma pack(8)*/
/*#pragma pack(0)*/
/*#pragma pack(7)*/
/*#pragma pack(3)*/
/*#pragma pack(1)*/ 	/* OK */
/*#pragma pack(2)*/	/* OK */
/*#pragma pack(4) 	/* OK */
/*#pragma pack(6)*/
#pragma pack(8)

struct foobar
{
	int a;
	char b;
	void * c;
	struct foo d;
	int e;

};


int main (int argc, char * argv[])
{
	struct foo t1;
	struct bar t2;
	struct foobar t3;
	
	printf ("offsetof foo.a = %d\n", offsetof (struct foo, a));	
	printf ("offsetof foo.b = %d\n", offsetof (struct foo, b));
	printf ("offsetof foo.c = %d\n", offsetof (struct foo, c));
	
	printf ("offsetof bar.a = %d\n", offsetof (struct bar, a));	
	printf ("offsetof bar.b = %d\n", offsetof (struct bar, b));
	printf ("offsetof bar.c = %d\n", offsetof (struct bar, c));
	printf ("offsetof bar.d.a = %d\n",offsetof (struct bar, d.a));
	printf ("offsetof bar.d.b = %d\n",offsetof (struct bar, d.b));
	printf ("offsetof bar.d.c = %d\n",offsetof (struct bar, d.c));
	printf ("offsetof bar.e = %d\n", offsetof (struct bar, e));

	printf ("offsetof foobar.a = %d\n", offsetof (struct foobar, a));
	printf ("offsetof foobar.b = %d\n", offsetof (struct foobar, b));
	printf ("offsetof foobar.c = %d\n", offsetof (struct foobar, c));
	printf ("offsetof foobar.d.a = %d\n",offsetof (struct foobar, d.a));
	printf ("offsetof foobar.d.b = %d\n",offsetof (struct foobar, d.b));
	printf ("offsetof foobar.d.c = %d\n",offsetof (struct foobar, d.c));
	printf ("offsetof foobar.e = %d\n", offsetof (struct foobar, e));

	t1.a = 0;
	t1.b = 1;
	t1.c = &t1;
	
	t2.a = 0;
	t2.b = 1;
	t2.c = &t1;
	
	t3.a = 0;
	t3.b = 1;
	t3.c = &t1;


	t2.d.a = 0xfabcde01;
	t2.d.b = 0xea;
	t2.d.c = (void *)0xdeadbeef;

	t3.d = t2.d;

	printf ("got 0x%08x 0x%2x 0x%08x\n", t3.d.a, t3.d.b, t3.d.c);

	t3.d.a = 0xabc123ea;
	t3.d.b = 0x11;
	t3.d.c = (void *)0xbeefdead;

	t2.d = t3.d;
	printf ("got 0x%08x 0x%2x 0x%08x\n", t3.d.a, t3.d.b, t3.d.c);
	
};


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