Re: pointer q



Joe Smith wrote:

<snip>

Thank you for replies. Mr. Thompson establishes that the reason not to swap an int * and long * is that, as usual, assigning one type to another is illegal, and that you can kludge away with castes if you so desire. Mr Kasak and Mr Sosman show examples of bad things that would happen if you did. What I'm trying to get my head around is how to view the memory with C. If it is true that memory is a bunch of boxes with numbers on the side and that different implementations may have differing sizes of pointers, then the numbers on the sides of those boxes are less homogenous than I thought. Joe

Don't think of memory as a bunch of boxes with numbers on the side. Don't think of memory at all. Think instead of arrays, ints and other objects just floating randomly in space 42 dimensional space (OK, you don't need to use that many dimensions). This will get rid of lots of misconceptions about pointers. For example, when objects can be left, right, above or below each other you start to see why you can't compare two pointer to see which is larger if they don't point in to the same object although you can always compare them for equality. Some of the boxes have names (the ones for variables you declare) and others are created by calling malloc.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
.



Relevant Pages