473,889 Members | 1,403 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
Arthur J. O'Dwyer wrote:
The Standard says that an object has a type.


malloc returns a pointer to a typeless nameless object.
Nov 13 '05 #291
Mark McIntyre wrote:
On Wed, 05 Nov 2003 01:46:09 GMT, in comp.lang.c , pete
<pf*****@mindsp ring.com> wrote:
int a;
&a;

(&a) is a pointer, but not an object.


I disagree. (&a) in that context is an expression. To be a pointer, it
would have to be stored in something. .


I think I'm going to have to ask for chapter and verse on that. Or I can
simply give you a counter-example: NULL. You see, NULL is most definitely a
pointer, and yet, in the expression if(p != NULL) the NULL is not "stored
in anything" - that is, the RHS of the != is not the value of 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 #292
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> writes:
On Wed, 5 Nov 2003, Sheldon Simms wrote:
An object is, by itself, only storage. It can store a value, but
doesn't have any inherent type or name.


The Standard says that an object has a type. Why else would we
discuss "objects of type T" and "objects of type U"?


The Standard does not say that. Here is the definition of
"object" in C99:

1 object
region of data storage in the execution environment, the
contents of which can represent values
2 NOTE When referenced, an object may be interpreted as having a
particular type; see 6.3.2.1.
--
"C has its problems, but a language designed from scratch would have some too,
and we know C's problems."
--Bjarne Stroustrup
Nov 13 '05 #293

On Wed, 5 Nov 2003, pete wrote:

Arthur J. O'Dwyer wrote:
The Standard says that an object has a type.


malloc returns a pointer to a typeless nameless object.


N869 disagrees with you, although it's quite possible
that the standard Standard :) changed the wording:
7.20.3.3 The malloc function

Synopsis
[#1]
#include <stdlib.h>
void *malloc(size_t size);

Description

[#2] The malloc function allocates space for an object whose
size is specified by size and whose value is indeterminate.

Returns

[#3] The malloc function returns either a null pointer or a
pointer to the allocated space.
"Pointer to allocated space", not "pointer to allocated object."
The allocated space is *big enough* to *hold* an object, but N869
significantly omits to say it actually *is* one. See?

Yeah, the Standard is kind of wishy-washy on this issue.
But it supports my opinion, which of course I think is only
common sense. :-)

-Arthur
Nov 13 '05 #294
pete wrote:

Sheldon Simms wrote:

Also, I think there is an important difference between the concepts
of "variable" and "object". A variable is a named, typed, object. An
object is, by itself, only storage.
It can store a value, but doesn't
have any inherent type or name.


The bit pattern stored in a nameless typeless object,
doesn't have any inherent value either.


After rereading the standard, I see that you are 100% correct
and I was wrong.

N869
6.2.5 Types
[#1] The meaning of a value stored in an object or returned
by a function is determined by the type of the expression
used to access it.

--
pete
Nov 13 '05 #295
Arthur J. O'Dwyer wrote:

On Wed, 5 Nov 2003, pete wrote:

Arthur J. O'Dwyer wrote:
The Standard says that an object has a type.

I see a definition of object that doesn't mention type.
"Pointer to allocated space", not "pointer to allocated object."


"allocated space", fits the definition of object.

N869
3. Terms and definitions
3.15
[#1] object
region of data storage in the execution environment, the
contents of which can represent values

--
pete
Nov 13 '05 #296
Mark McIntyre <ma**********@s pamcop.net> writes:
On Wed, 05 Nov 2003 01:46:09 GMT, in comp.lang.c , pete
<pf*****@mindsp ring.com> wrote:
int a;
&a;

(&a) is a pointer, but not an object.


I disagree. (&a) in that context is an expression. To be a pointer, it
would have to be stored in something. .


The standard does not define the term "pointer", but it often
uses it with the implied meaning of "value of pointer type". For
example, take this paragraph from C99 6.3.2.3:

7 A pointer to an object or incomplete type may be converted to a
pointer to a different object or incomplete type. If the
resulting pointer is not correctly aligned57) for the
pointed-to type, the behavior is undefined. Otherwise, when
converted back again, the result shall compare equal to the
original pointer. When a pointer to an object is converted
to a pointer to a character type, the result points to the
lowest addressed byte of the object. Successive increments
of the result, up to the size of the object, yield pointers
to the remaining bytes of the object.

Each use of "pointer" in this paragraph means "value of pointer
type", because the alternative, that each of them means "object
of pointer type", doesn't make sense. A few of them are
debatable, but all of them taken together should make it clear
that a pointer can be a value.
--
"The lusers I know are so clueless, that if they were dipped in clue
musk and dropped in the middle of pack of horny clues, on clue prom
night during clue happy hour, they still couldn't get a clue."
--Michael Girdwood, in the monastery
Nov 13 '05 #297
On 5 Nov 2003 21:57:18 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.hel sinki.fi> wrote:
Mark McIntyre <ma**********@s pamcop.net> scribbled the following:
On Wed, 05 Nov 2003 01:46:09 GMT, in comp.lang.c , pete
<pf*****@mindsp ring.com> wrote:
int a;
&a;

(&a) is a pointer, but not an object.

I disagree. (&a) in that context is an expression. To be a pointer, it
would have to be stored in something. .


This depends on the definition of a "pointer".


As far as I'm concerned, a pointer is an object that points to
something else, either another object, or a function, or nothing.

Mornington Crescent.

--
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 #298
On Wed, 5 Nov 2003 22:41:16 +0000 (UTC), in comp.lang.c , Richard
Heathfield <do******@addre ss.co.uk.invali d> wrote:
Mark McIntyre wrote:
On Wed, 05 Nov 2003 01:46:09 GMT, in comp.lang.c , pete
<pf*****@mindsp ring.com> wrote:
int a;
&a;

(&a) is a pointer, but not an object.
I disagree. (&a) in that context is an expression. To be a pointer, it
would have to be stored in something. .


I think I'm going to have to ask for chapter and verse on that. Or I can
simply give you a counter-example: NULL. You see, NULL is most definitely a
pointer,


Well..... NULL is a macro, which is converted by the preprocessor to a
constant inserted literally into the processed code, whose value is
selected to be the one the implementation uses to mean "I point
nowhere". So its not actually a pointer at this point. If you see my
point.

and yet, in the expression if(p != NULL) the NULL is not "stored
in anything" - that is, the RHS of the != is not the value of an object.


But thats fine - its not a pointer either... :-)
--
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 #299
Mark McIntyre <ma**********@s pamcop.net> writes:
On 5 Nov 2003 21:57:18 GMT, in comp.lang.c , Joona I Palaste
<pa*****@cc.hel sinki.fi> wrote:
This depends on the definition of a "pointer".
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.
Mornington Crescent.


I have no idea what that means. Is it a breakfast food?
--
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 #300

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.