Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
* gcc  Alpha/Intel incompatibility
@ 1998-03-06  5:00 Arun Sharma
  1998-03-06  5:00 ` Arun Sharma
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Arun Sharma @ 1998-03-06  5:00 UTC (permalink / raw)




The following program compiles on Intel but fails to compile on
Alpha. I've tried both gcc-2.7.2.3 and egcs-1.0.1.

Can someone tell me why ?

	-Arun

extern int f(char);

typedef struct foo1 {
	int i;
	char c;
} f1;


typedef struct foo2 {
	int (*foo_func)(char);
	int j;
} f2;

typedef struct foo {
	f1 F1;
	f2 F2;
} mytype;

mytype foo1 = {
	{ 10, 'c'},
	{(int) f, 20}
};



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcc  Alpha/Intel incompatibility
  1998-03-06  5:00 gcc Alpha/Intel incompatibility Arun Sharma
@ 1998-03-06  5:00 ` Arun Sharma
  1998-03-06  5:00 ` David.Mosberger
  1998-03-07  5:00 ` Ed Hall
  2 siblings, 0 replies; 4+ messages in thread
From: Arun Sharma @ 1998-03-06  5:00 UTC (permalink / raw)




Oops, forgot to add the error message:

$ cc -c foo.c
foo.c:21: initializer element for `foo1.F2.foo_func' is not computable
at load time

	-Arun



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcc  Alpha/Intel incompatibility
  1998-03-06  5:00 gcc Alpha/Intel incompatibility Arun Sharma
  1998-03-06  5:00 ` Arun Sharma
@ 1998-03-06  5:00 ` David.Mosberger
  1998-03-07  5:00 ` Ed Hall
  2 siblings, 0 replies; 4+ messages in thread
From: David.Mosberger @ 1998-03-06  5:00 UTC (permalink / raw)
  To: asharma


Arun Sharma <asharma@netscape.com> writes:

> The following program compiles on Intel but fails to compile on
> Alpha. I've tried both gcc-2.7.2.3 and egcs-1.0.1.
> 
> Can someone tell me why ?
> 
> 	-Arun
> 
> extern int f(char);
> 
> typedef struct foo1 {
> 	int i;
> 	char c;
> } f1;
> 
> 
> typedef struct foo2 {
> 	int (*foo_func)(char);
> 	int j;
> } f2;
> 
> typedef struct foo {
> 	f1 F1;
> 	f2 F2;
> } mytype;
> 
> mytype foo1 = {
> 	{ 10, 'c'},
> 	{(int) f, 20}
> };

Remove the cast to "int" and it will compile.  On a 64-bit platforms
such as Linux/Alpha, a pointer does not fit into an int, hence the
error message.  If the source of your real problem is initialization
of a union, there are several options to fix the problem (reorder the
members in the union, depend on a gcc-specific extension to initialize
unions, or use longs instead of ints).

	--david



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gcc  Alpha/Intel incompatibility
  1998-03-06  5:00 gcc Alpha/Intel incompatibility Arun Sharma
  1998-03-06  5:00 ` Arun Sharma
  1998-03-06  5:00 ` David.Mosberger
@ 1998-03-07  5:00 ` Ed Hall
  2 siblings, 0 replies; 4+ messages in thread
From: Ed Hall @ 1998-03-07  5:00 UTC (permalink / raw)



Arun Sharma (asharma@netscape.com) wrote:

: The following program compiles on Intel but fails to compile on
: Alpha. I've tried both gcc-2.7.2.3 and egcs-1.0.1.

: Can someone tell me why ?

It's invalid code.  You cast the pointer-to-function initializer
to an "int":

    mytype foo1 = {
        { 10, 'c'},
        {(int) f, 20}
    };

Change this to:

    mytype foo1 = {
        { 10, 'c'},
        { f, 20}
    };

and it compiles fine.

On an Alpha, it is impossible to represent a function pointer (a
64-bit quantity) with an int (a 32-bit quantity).  Thus the
initializer fails, whereas on Intel where sizeof(pointer) ==
sizeof(int) you only get a warning.  You DID see the warning,
didn't you?

Admittedly, the error is cryptic, even misleading.  In that
sense, it's a bug.  But GCC is hardly alone in sometimes
getting confused when faced with invalid programs...

                -Ed Hall
                edhall@ayched.com



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-03-07  5:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-03-06  5:00 gcc Alpha/Intel incompatibility Arun Sharma
1998-03-06  5:00 ` Arun Sharma
1998-03-06  5:00 ` David.Mosberger
1998-03-07  5:00 ` Ed Hall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox