[gnu.gcc.bug] Can't I cast a struct to an int?

rfg@MCC.COM (Ron Guilmette) (01/26/89)

Should the following code be considered illegal?  GCC 1.32 seems to
think so, and it gives me the following error message:

x01.c: In function main:
x01.c:14: aggregate value used where an integer was expected

=====================================================================
/*
Description - check that struct values may be cast to built-in types
		(such as int).
*/

struct node {
  int f1;
};

struct node global_node;

void main()
{
  int casted = (int) global_node;
  exit (0);
}
=====================================================================

I think that this should be allowed (perhaps even if ANSI disagrees).
After all, isn't C supposed to be the language that treats you like
a grownup, and assumes that you should be allowed to do what you want
to because you presumably know what you are doing?

Allowing the form of casting shown above would certainly seem to be a very
easy thing to implement.

I can work around this, but it looks ugly.  Basically, I have to resort
to a different way of tricking the type system, i.e.:

=====================================================================
struct node {
  int f1;
};

struct node global_node;

static int tricky_conversion();

void main()
{
  int casted = tricky_conversion (global_node);
  exit (0);
}

static int tricky_conversion (i)
int i;
{
	return i;
}
=====================================================================