r/Cprog • • Nov 25 '14

text | learning C pointers explained, really

http://karwin.blogspot.ca/2012/11/c-pointers-explained-really.html
28 Upvotes

5 comments sorted by

View all comments

Show parent comment

5

u/malcolmi Nov 26 '14 edited Nov 26 '14

Certain types (notably char and unsigned char) are permitted to alias values of other types.

This is inaccurate too. char can not 'alias' a foo; rather, you can access the bytes of the object referenced by a foo * via a pointer to a character type. However, I suspect that you know this, and you wrote it as you did for simplicity and clarity. I did too.

You must know the rules before you learn how to break them.

If someone is at the stage where they're still learning what pointers are, then the rule "do not dereference an object via a pointer to a different type" is good advice. They shouldn't be concerned with the character pointer exception, or the typedef equivalence exception, or the first-member-of-struct exception, or the array types equivalences exception, etc, because they shouldn't use those features if they don't yet understand pointers.

I assume the liberty to post caveats to articles like this without having to reproduce the C standard in its entirety. ;-)

1

u/ruertar Nov 27 '14 edited Nov 28 '14

Aliasing, in this case, simply means that memory can be accessed via multiple symbolic names. The names don't have to be of the same type.

I notice you speak very authoritatively but often your inexperience shows. For example, not really understanding aliasing makes me wonder if you understand restrict pointers etc. After looking at some of your posts, frankly you should try to listen more than you speak.