473,889 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Mastering C Pointers"....

Hey guys, I'm new here, just a simple question.

I'm learning to Program in C, and I was recommended a book called,
"Mastering C Pointers", just asking if any of you have read it,
and if it's worth the $25USD.

I'm just looking for a book on Pointers, because from what I've
read it's one of the toughest topics to understand.

thanks in advanced.

sincerely ... Andy
Nov 13 '05
388 21994
Roose wrote:

"Richard Heathfield" <do******@addre ss.co.uk.invali d> wrote in message
news:bo******** **@titan.btinte rnet.com...
Roose wrote:
> Let me ask what is silly about claiming that I have posted in this
> newsgroup with different names before.
Well, did you really expect anyone to believe you, after your amazingly
clueless entry into the newsgroup?


Please do not quote out of context, in an attempt to divert the
discussion,
as you have made a recent habit of doing.


Huh? The context I snipped was irrelevant to your question.
This is irrelevant to the
question at hand, which is whether my argument was logically consistent.
Ah. I thought the question at hand was the question you actually asked.
Sorry if I misunderstood you. Okay, is your argument logically consistent?
No.
So, let me suggest that you are the one who "resorts to abuse when you run
out of logic".
How have I abused you, precisely? If you recall, I answered your C question
and politely asked you not to top-post. Since then, I've had nothing but
hostility from you. I think I've been rather patient with you, actually.
This hypocrisy thing keeps coming back to bite you.


I've already admitted that I'm about as hypocritical as the next man. But
let me read between the lines (or line, in this case)... Are you actually
claiming that you, alone of all humans, are free from hypocrisy? Are you
*really* as hypocritical as that? Sorry, but I don't - I /can't/ - believe
it of you.

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 13 '05 #251
"Roose" <no****@nospam. nospam> wrote in message news:<TR******* **********@news svr14.news.prod igy.com>...
After reading the first 1/3 carefully, it seems to me that a pointer is very
much like a symlink.


Uh, I'm not exactly sure what a symlink is, but if it is anything like a
Windows shortcut, there is definitely an analogy there.

The windows shortcut just stores the location of a file. A "pointer" to it.
An address. The address is the _path name_. In C, the "address" is
basically an integer,


no, it isn't *always* an integer type. in x86 real-mode it is *two*
integer types.
indicating where in a huge array of memory the
variable is.

You can have as many shortcuts as you want that point to the file. A
shortcut takes a small amount of storage, but not as much as a (typical)
file. You can have whole directories of shortcuts that point to files all
over the place, in order to organize them. Likewise, you can have
collections of pointers, that point to various different things _scattered_
all over memory.

For example, on my hard disk, I have a whole bunch of (legal) MP3s organized
by artist and by album. Now, some of them were ripped poorly and have
clicks. So I *could* just copy those files to another folder, in order to
note that I need to rip them again.

However, it is *much* easier and efficient to just copy shortcuts those bad
files into another folder -- called "bad". That way I don't duplicate any
data. And I have all the bad files organized in one directory, and can
access them easily.

You could do the exact same thing with pointers. Suppose I had a whole
bunch of strings in memory, that listed a ton of song names. I could create
an array of pointers called "theBeatles " that pointed to every single song
by the Beatles. Then I could have an array of pointers called "badFiles"
that pointed to all the bad files, _some of which_ may be by the Beatles.
Note that I haven't incurred the storage cost of repeating the strings,
*just* pointers to them. Likewise I could create another array called
"before1960 " that points to all songs stored before 1960 -- you get the
idea.

Hm, I'm surprised this didn't come up earlier. This is an easy analogy.


but not entirely accurate. this is because you cannot do "shortcut
arithmetic" but you /can/ do pointer arithmetic.

<to OP>

a pointer variable holds an address of an object. for example
a "pointer to char" can hold the addess of a char, and a
"poniter to int" can hold the address of an int. to access
the object itself, one must dereference the pointer.

dereferencing means "get the object at that address". for example:

/* we declare an object of type int */
int foo = 12;

/* we declare a pointer to int */
int *bar;

/* now we set bar to point to foo, using the address of operator */
bar = &foo;

/* foo still contains 12, while bar contains the address of foo.
now we dereference bar to get the value of foo (namely, 12) */
printf ("bar points to foo which has number %i\n", *bar);
/* that would have printed
"bar points to foo which has number 12."
*/

hth
goose,
busy as can bee
Nov 13 '05 #252
> > This is irrelevant to the
question at hand, which is whether my argument was logically consistent.


Ah. I thought the question at hand was the question you actually asked.
Sorry if I misunderstood you. Okay, is your argument logically consistent?
No.


Let's hear a reason for this, please. My assertion is that I have posted
here before, but not under the handle Roose.

What, exactly, is "silly" about this, regardless of its truth. I know you
doubt me, as you have stated, but you can simply say so (and you did). But
instead you chose, embarassingly, to try to debunk my argument with a series
of silly statements yourself. Like the fact that I must be "non-existent",
etc. and similar blabber.
This hypocrisy thing keeps coming back to bite you.


I've already admitted that I'm about as hypocritical as the next man. But
let me read between the lines (or line, in this case)... Are you actually
claiming that you, alone of all humans, are free from hypocrisy? Are you
*really* as hypocritical as that? Sorry, but I don't - I /can't/ - believe
it of you.


Wow, Richard is reading between the lines finally! But no, I make no such
claim of myself, only that you have obviously been a hypocrite.
Nov 13 '05 #253
Irrwahn Grausewitz <ir*******@free net.de> wrote in message news:<to******* *************** **********@4ax. com>...
Mark McIntyre <ma**********@s pamcop.net> wrote:
On Tue, 04 Nov 2003 22:29:03 GMT, in comp.lang.c , Alan Connor
<zz****@xxx.yyy > wrote:
<snip>
If only you stopped there, which you obviously don't. Another lie.


Okay, enough. You're either a total idiot, or you're a troll.


Apparently he's both, see below.
Only one or the other would call Keith Thompson AND Richard Heathfield
liars within a single post. For our amusement as much as your own
enlightenment, you might want to google for the history of their
posts,


I had some spare time and did a quick google groups search. If you're
only interested in the highlights, do a search for threads that have his
name in the _subject-line_. For the full load perform a search for
articles he posted. It's real fun.


and the choicest flame ever award (and to save others the trouble of
googling) goes to Pierre Honeyman:

---------------------------------------------------------------------------
From: Pierre Honeyman (ph*******@telu s.net)
Subject: Alan Connor, Uber-Idiot

View: Complete Thread (3 articles)
Original Format

Newsgroups:
rec.martial-arts
Date: 2003-11-04 15:44:59 PST

It's the latest entry into RMAs ongoing TrollMatch.

A man who has taken the whole "Hate America First" extremism to a
whole new level. A man who has decided to just hate the whole human
race, because wolves are obviously smarter and more humane. A man who
can afford a computer, a phone line, and an internet account on
$200/year - in the US. A man so powerful in the mighty art of Tai
Chen (which he's studied for a whole year now) that he is invulnerable
to either the sword's stab or the hunter's bullet. A man so righteous
that his killfile causes pain. A man so omnipotent that he will reply
to people *he has already killfiled*.

It's Alan Connor.

He's a strong entry in an already strong field. Competing against
well established entrants, he'll have to stick around to really score
some points with the more cynical judges, but his opening moves have
been well received by all.

Will he be able to maintain his formidable momentum? Only time will
tell.

He's a well known idiot in other groups, but can he make it here?

Pierre

---------------------------------------------------------------------------
<snip>
And I think you are a liar, and am sick of this continued smear campaign
against Roose.
You /are/ roose. I claim my five pounds.


the sad part is that "roose" is only one letter away from "goose" :-(

(btw: "roose" is an intentional troll, ever considered that
"roose" is just a mispelled "ruse"?)

I still don't think so.
*plonk*


And miss the fun? Naw...


i should have read the whole thread through before trying to
be helpfull. I've wasted precious time today.

goose,
the non-troll type
Nov 13 '05 #254
>Chris Torek <no****@elf.eng .bsdi.com> writes:
For something really different, I would suggest trying[list of
"different" machines]

In article <3F************ ***@yahoo.com> CBFalconer <cb********@yah oo.com>
writes:Shouldn't the HP3000 running MPE fit in there somewhere? I
believe it just became unsupported. Many Burroughsisms. It DID
have a C compiler 25 years ago.
Well, 25 years ago was 1987, which predates ANSI C, but mainly I
did not list it because I never used it nor even read much about
it. (I have not used the AS/400 either, but I have read a bit from
those who have.) I think certain Tandem machines might also fit
in the "oddball" category.

In article <lz************ @cts.com> Keith Thompson <ks*@cts.com> wrote:Another good example is the Cray vector machines (T90, SV1, et al).
As far as the C compiler is concerned, bytes are 8 bits, but all
integer types other than the char types are 64 bits. Native addresses
point to 64-bit words. A byte pointer is formed by storing a 3-bit
byte offset in the high-order bits of a 64-bit word pointer.
As I recall from discussions long ago on comp.std.c, this was just
one of two ways to handle "byte pointers" on Crays. (The other
was Eclipse-style shifting for pointer conversions. Perhaps this
method was used on different hardware.)
Pointer arithmetic works just fine, but I've seen non-portable
code that tried to do arithmetic on a pointer by casting it to an
integer type, performing integer arithmetic on it, and casting it
back. It didn't work.


Indeed. However, the AS/400 covers this same case in what I think
is a more eye-opening manner: performing such pointer arithmetic
tricks results in a pointer that traps when used, and perhaps in
some cases, even when simply assigned. (The reason is that the
"capability " portion of the pointer -- the part that determines
access permissions -- simpy disappears, so you are left with an
invalid pointer, even if it has the right "value" bits.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #255
On Tue, 04 Nov 2003 21:05:17 +0000, Joona I Palaste wrote:
You mean the time RJH told Dennis Ritchie he (DMR, not RJH) was off
topic? Yes, that really happened.


Is that archived somewhere? Google? Somewhere else?

--
NPV

"the large print giveth, and the small print taketh away"
Tom Waits - Step right up

Nov 13 '05 #256
"Roose" <no****@nospam. nospam> writes:
"Keith Thompson" <ks*@cts.com> wrote in message
news:lz******** ****@cts.com... [...]
I don't think anybody here has claimed that all C code must be
strictly conforming, or that non-portable code is evil. Non-portable
code is sometimes necessary. But I've found that clean code tends to
be portable, and vice versa. If you develop the right habits, writing
portable code really isn't all that difficult. But when you write
code that depends on the characteristics of a particular system,
you've left the scope of this newsgroup, and if you have any questions
about it, you're more likely to get correct answers in a newsgroup
devoted to that system.


I can agree with that, but my impression is that this reasonable stance is
not the one that the majority of those in this newsgroup take.


Actually, I believe it is. Anyone who disagrees should feel free to
jump in.

[...]
Not specifically, but imagine a program that operates on a pointer in
a manner that only works if pointers are just integers. When the
program is ported to a system where that's not the case, it generates
pointer values that point to random locations in memory. If it writes
a value through such a pointer, it can clobber some arbitrary
variable. Sometimes this may be harmless, but sometimes, depending on
the circumstances, the result can be drastic.


I undestand this, but again my contention is that such bugs would be quite
obvious. Code that depends on this simply would not work when ported and
tested for this first time. But as a practical matter, there is a large
percentage of systems (if anyone would like to offer a guess, I would be
interested), where you can assume this.


No, in real life, such bugs are often not obvious. Vendors release
patches for software bugs all the time. What do you think causes
those bugs? And why do you think they weren't found in testing before
the software was released in the first place?
But my larger point stands, that for pedagogical purposes, it is a useful,
concrete statement to say that a pointer is not unlike an array index. An
integer. Yes there can be other bits set, and so forth. But if you were a
C programmer who was NOT aware of this fact, I would seriously question you.


A C programmer should be aware that pointers are represented as
integers on many systems, and are represented similarly to integers on
many others, but he should be able to write code that doesn't depend
on this knowledge. As several of us have said, writing portable code
can actually be easier than writing gratuitously non-portable code.

You yourself gave an example of a program that you said depends on the
non-portable assumption that pointers are represented as integers
(serializing data by converting pointers to numeric offsets before
writing out a data structure). I demonstrated how the same thing
could be done just as easily in portable C, using only the properties
of pointers defined by the language. The solution I outlined would
work even on the unusual systems we've been discussing with bizarre
pointer representations .

--
Keith Thompson (The_Other_Keit h) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #257
Nils Petter Vaskinn <no@spam.for.me .invalid> scribbled the following:
On Tue, 04 Nov 2003 21:05:17 +0000, Joona I Palaste wrote:
You mean the time RJH told Dennis Ritchie he (DMR, not RJH) was off
topic? Yes, that really happened.
Is that archived somewhere? Google? Somewhere else?


Try this:
http://groups.google.com/groups?q=De....co.uk&rnum=26

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"B-but Angus! You're a dragon!"
- Mickey Mouse
Nov 13 '05 #258
"Nils Petter Vaskinn" <no@spam.for.me .invalid> wrote in message news:pa******** *************** ***@spam.for.me .invalid...
On Tue, 04 Nov 2003 21:05:17 +0000, Joona I Palaste wrote:
You mean the time RJH told Dennis Ritchie he (DMR, not RJH) was off
topic? Yes, that really happened.


Is that archived somewhere? Google? Somewhere else?


http://groups.google.c om/gr************* *************** ***********@eto n.powernet.co.u k
http://groups.google.c om/gr************* *************** ***********@eto n.powernet.co.u k

--
Peter
Nov 13 '05 #259
ru**@webmail.co .za (goose) wrote:
the sad part is that "roose" is only one letter away from "goose" :-(

(btw: "roose" is an intentional troll, ever considered that
"roose" is just a mispelled "ruse"?)


Yes, I did indeed, but ruse's and Roose's postings are definitely of
different style. And I do not consider either one to be smart enough
to successfully pretend to be somebody else.

Remember ruse: "... again, spoke your nose!" makes me still ROFL. :D
--
Irrwahn
(ir*******@free net.de)
Nov 13 '05 #260

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.