difference between punning and aliasing 
Author Message
 difference between punning and aliasing


Quote:
> Hi...

> What's the _conceptual_ difference
> between punning and aliasing?

Punning is lying to your compiler about the type.  Sometimes, it's perfectly
sensible.  For instance, you might have an unsigned char pointer and a
function wants a signed char pointer.  You happen to know (for instance by
examining the original source) that it will work fine for your function.  So
you cast the call and off you go.  There are some other ways this is done,
often much riskier.  For example, addresses are passed in longs.  This one is
obviously highly risky.  Punning means that you are saying that one type is
really another.  Any time you do this, you had better be darned sure it will
work.  It is really an indication of bad design if it happens a lot.

Aliasing means that you are using a pointer to an object.  Think "Alias Smith
and Jones" -- it's just another name for the same object.  This has a separate
set of issues associated with it.  The biggest problem is that it can harm
optimization.  Consider some matrix m.  If several pointers to m are floating
around, your compiler cannot assume "no aliasing".  This can be a problem to
make optimal binaries.  With the latest C standard there is a compiler hint
that an object is not aliased.  I have no idea what it does, since I have
never tried to use it -- or even if any compilers support it yet.
--
C-FAQ: http://www.*-*-*.com/ ~scs/C-faq/top.html
 "The C-FAQ Book" ISBN 0-201-84519-9
C.A.P. FAQ: ftp://cap.connx.com/pub/Chess%20Analysis%20Project%20FAQ.htm



Mon, 19 May 2003 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. difference between punning and aliasing

2. Some questions about C (punning, side effect, ...)

3. punning unions

4. a heap of questions (pun intended)

5. Type punning in C

6. Aliasing through union, C++ vs. C

7. ANSI aliasing rules

8. Aliasing question...

9. Aliasing in ANSI C

10. Aliasing and character types

11. Sequence Points, Aliasing & Optimisation

12. aliasing single quotes in macros

 

 
Powered by phpBB® Forum Software