473,889 Members | 1,394 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 22005
Mark McIntyre <ma**********@s pamcop.net> writes:
On 05 Nov 2003 15:44:56 -0800, in comp.lang.c , Ben Pfaff
<bl*@cs.stanfor d.edu> wrote:
Mark McIntyre <ma**********@s pamcop.net> writes:
As far as I'm concerned, a pointer is an object that points to
something else, either another object, or a function, or nothing.


See my post elsethread for why that's a bad definition.


I must have either completely missed that post, or misunderstood it.
Could you paraphrase?


I quoted a paragraph from the standard that used the word
"pointer" several times to mean "value of pointer type". If the
standard doesn't always use "pointer" as meaning "object of
pointer type", then I don't think it's reasonable to define it
that way.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 13 '05 #331
On Thu, 6 Nov 2003 06:56:10 +0000 (UTC), in comp.lang.c , Richard
Heathfield <do******@addre ss.co.uk.invali d> wrote:
Surely you mean "cranking /in/ the data"?

Data is (or are!) what you put into a computer. What it cranks out is
information.
Ah, so whats the difference between the stuff that comes out of a 1401
and goes into a 7094? Does it magically get transmogrified during the
technician's walk down the hall with the tape?*
Well, that's the general idea, anyway.


Hmmmm. I find this distinction highly artificial.

* for anyone under about 60, a 1401 is an IBM computer which was
typically used to read punched cards and transfer the results to
tape, which was then fed into a larger IBM, such as a 7094.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #332
On Thu, 06 Nov 2003 16:38:57 -0700, Chris Torek wrote:
"Chris Torek" <no****@elf.eng .bsdi.com> wrote in message
news:bo****** ****@elf.eng.bs di.com...


For the curious, the "compensati on" code for a negative dividend
(and positive divisor) -- remember in x / y, x is the dividend and
y is the divisor -- works out to the following, all assuming 2s
complement and an arithmetic right-shift:

/* divide signed input "x" by divisor, whose log2 is d2 */
int divide_by_power _of_two(int x, int divisor, int d2) {
int adj;

/* required: (1 << d2) == divisor */
adj = (x & SIGNBIT) ? divisor - 1 : 0;
return (ux + adj) >> d2;
}


There was actually a really good example of this a few days ago
here in the thread about computing integer powers. The following
function was presented:

static int pow_a(int x, int y)
{
int t=1;

if (y < 0) return 0;
for(;;)
{
if (y%2) t*=x; /* if y is odd... */
if (!(y/=2))break; /* halve y and if result is zero... */
x*=x; /* square x */
}

return t;
}

While testing this and the other functions, I was read the output
of GCC for all of the functions because I was curious why some
functions seemed to run faster even though the C code was
apparently equivalent. The y/=2 in the second if conditional
is turned into the following x86 code by GCC 3.3.1:

movl %edx, %eax ; temp = y
shrl $31, %eax ; temp >>= 31
leal (%eax,%edx), %eax ; temp = temp + y
sarl %eax ; temp >>= 1;
movl %eax, %edx ; y = temp

-Sheldon
Nov 13 '05 #333
>On Thu, 06 Nov 2003 16:38:57 -0700, Chris Torek wrote:
For the curious, the "compensati on" code for a negative dividend ... [with "int x, adj, divisor", and assuming two's complement] adj = (x & SIGNBIT) ? divisor - 1 : 0;

In article <pa************ *************** @yahoo.com>,
Sheldon Simms <sh**********@y ahoo.com> wrote:... I was read the output of GCC for [various] functions [and found]
y/=2 in the second if conditional is turned into the following x86
code by GCC 3.3.1:

movl %edx, %eax ; temp = y
shrl $31, %eax ; temp >>= 31
leal (%eax,%edx), %eax ; temp = temp + y
sarl %eax ; temp >>= 1;
movl %eax, %edx ; y = temp


Yes, this is a special case of the code I suggested. We want
"adj = (x & SIGNBIT) ? (2 - 1) : 0", and of course 2 - 1 is 1. I
had suggested the general case would use (for x86) "sarl $31, %eax"
and then "and $1, %eax", but note that if we use a logical shift
instead of an arithmetic shift, the values we get for "is signed"
and "is not signed" are 1 and 0 respectively, instead of -1 and 0.

In (nonportable) C this would be:

/* adj = (x >> 31) & (divisor - 1); -- general case */
adj = (unsigned)x >> 31; /* specific case when divisor==2 */

This allows the compiler to omit the "and" instruction. (The
nonportable parts are twofold: this assumes x is a 32 bit two's
complement value; and it assumes that signed ">>" sign-extends.
The first part is easy to parameterize, but the second is not.)

(The "leal" instead of "add" is another fairly disgusting trick that
avoids pipeline constraints in some cases, I believe.)
--
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 #334
Mark McIntyre <ma**********@s pamcop.net> wrote in message news:<j9******* *************** **********@4ax. com>...
On Thu, 6 Nov 2003 07:59:34 +0000 (UTC), in comp.lang.c , Richard
Heathfield <do******@addre ss.co.uk.invali d> wrote:
goose wrote:
Joona I Palaste <pa*****@cc.hel sinki.fi> wrote in message
news:<bo******* ***@oravannahka .helsinki.fi>.. .

TIWITAW.

<all confused>
FWIW, IUWJM


"for what its worth", and then ?

BUAATOO, IR.


??

goose,
tia :-)
Nov 13 '05 #335
Mark McIntyre wrote:
But thats fine - its not a pointer either... :-)


The Standard disagrees with you.


I disagree that it disagrees. In order to compare p to NULL, you must
convert p to a pointer type (see quote above, plus 6.3.2.3-4). I'm
doubtful that you could convert a null pointer constant to a pointer
type without storing it somewhere....


You make a better case than I thought existed. Lacking the time right now to
make a detailed study of the matter, so I hope someone else picks it up.
I'm not quite so doubtful as you are about the conversion. After all, on
some implementations it's a no-op. Would you suggest that, say, 0 is an
object?

--
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 #336
Mark McIntyre wrote:
On Thu, 6 Nov 2003 06:56:10 +0000 (UTC), in comp.lang.c , Richard
Heathfield <do******@addre ss.co.uk.invali d> wrote:
Surely you mean "cranking /in/ the data"?

Data is (or are!) what you put into a computer. What it cranks out is
information .


Ah, so whats the difference between the stuff that comes out of a 1401
and goes into a 7094? Does it magically get transmogrified during the
technician's walk down the hall with the tape?*


Think of them as being part of the same computer system, with the technician
being a rather slow, but high-capacity, data bus.
Well, that's the general idea, anyway.


Hmmmm. I find this distinction highly artificial.


Data are the raw materials of information.

--
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 #337
In article <bo**********@e lf.eng.bsdi.com >,
Chris Torek <no****@elf.eng .bsdi.com> wrote:
On a typical RISC we get something like:

mov x, reg # assuming x is already in a register
asr reg, 31, reg # where asr is arithmetic shift right
and reg, 3, reg # for divisor == 4
add reg, x, reg
asr reg, 2, reg # again for divisor == 4
# final result is now in "reg"


On a PowerPC, you get:
int test (int x) { return x / 4; }

00000000: 7C601670 srawi r0,r3,2 // r0 = r3 >> 2
00000004: 7C600194 addze r3,r0 // r3 = r0 + 0 + carry
00000008: 4E800020 blr // Return
Nov 13 '05 #338
goose wrote:
Mark McIntyre <ma**********@s pamcop.net> wrote in message
news:<j9******* *************** **********@4ax. com>...
On Thu, 6 Nov 2003 07:59:34 +0000 (UTC), in comp.lang.c , Richard
Heathfield <do******@addre ss.co.uk.invali d> wrote:
>goose wrote:
>
>> Joona I Palaste <pa*****@cc.hel sinki.fi> wrote in message
>> news:<bo******* ***@oravannahka .helsinki.fi>.. .
>>>
>>> TIWITAW.
>>
>> <all confused>
>
>FWIW, IUWJM

"for what its worth", and then ?


"I Understood What Joona Meant."

The J was the clue.

BUAATOO, IR.

??


Yeah, that's got me stumped as well.

goose,
tia :-)


In my country, that's the name of a drink. :-)

--
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 #339
Greetings.

In article <qm************ *@newssvr14.new s.prodigy.com>, Roose wrote:
My assertion is that I have posted
here before, but not under the handle Roose.


Let me guess: your previous handles on this group were Karl Malbrain,
Ioannis Vranos, and Scott Nudds. What do I win?

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Nov 13 '05 #340

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.