[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] More on aliasing.

From: Anthony Carrico
Subject: Re: [Chicken-users] More on aliasing.
Date: Mon, 8 Jul 2002 14:24:00 -0400 (EDT)

On Mon, 8 Jul 2002, Peter Keller wrote:

> However, it doesn't work if sizeof(void*) != sizeof(C_word) because
> you'll lose information. That was my main point.

I'm sorry, I think I received the messages out of order, and posted before
I saw your original message. Thank you for explaining the issue.

Let's assume that void* and int really are different sizes. When do you
lose information? Let me redefine the union:
  union word_t
    void* ptr;
    int integer;
  word_t w1 = ...;
  word_t w2;
  int i;
  int j;
  void* p;
  void* bad;

I assume you are ok if you always assign the whole union (like this):
  w2 = w1;
or if you assign a known integer:
  w2.integer = i;
  j = w2.integer;
or if you assign a known pointer:
  w2.ptr = &i;
  p = w2.ptr;
I think you can only get in trouble if you assign an integer and retreive
a pointer:
  w2.integer = i;
  bad = w2.ptr;
or vise versa. In other words, when you actually do commit a (dynamic)
type error. Is this correct?

On Mon, 8 Jul 2002, felix wrote:

> Yep, many times. Internally everything is handled with C_word objects,
> Also, the FFI does a lot of dirty casting between pointers and C_word's.

Is there any reason to assume the C compiler is better off casting and
masking instead of using unions + bitfields + structs? It seems to me (at
least in theory) that the more accurate the information you share with the
compiler the better. This is the kind of thing C is supposed to be good
at. (Obviously it would be a lot of work to actually change the code

  -Tony Carrico

reply via email to

[Prev in Thread] Current Thread [Next in Thread]