"Mastering C Pointers"....

I

Irrwahn Grausewitz

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
 
I

Irrwahn Grausewitz

Richard Heathfield said:
Problem: an object that holds a pointer value need not be a variable. For
example:

int i = 6;
int * const p = &i; /* p is not a variable - or at least, to persuade anyone
that it is, you'd have to have kissed the Blarney. */

But it's not a 'real' constant either. Now, what is it? (rhetorical
question) After all it's an lvalue, yet, const qualified as it is, not
modifiable.

It appears to me that Ben Pfaff's suggestion (in reply to my post) is
the most useful and accurate one:

"objects of pointer type" or "pointer objects"

and

"values of pointer type" or "pointer values"

Regards
 
P

pete

Sheldon Simms wrote:
Pointers can be valid or invalid.
A valid pointer has a value that points to
an existing object.
An invalid pointer has a value that does not point to an
existing object.

I like your essay.

There's also the matter of the "one past" pointer.

char variable = 0;
char other;

(&variable + 1); /* defined */
(&variable + 1 > &variable); /* defined, true */
(&variable + 1 != &other) /* defined */
*(&variable + 1); /* undefined, regardless
** if (&variable + 1 == &other)
*/
 
G

goose

Mark McIntyre said:
And of course a null pointer is a pointer that doesn't point to
anythin....

And are functions objects?

iirc, yes.
So can we settle on "a pointer is an object that can probably point to
another object, or possibly to a function, which is possibly not an
object, ouch my head hurts"?
:)

<grin>
or even more convoluted, how about
"a pointer is an /object/ whose legal values can only be /addresses/
of other objects" ?

goose,
is there no textbook (c-std) definition ?
 
P

pete

goose said:
iirc, yes.


<grin>
or even more convoluted, how about
"a pointer is an /object/ whose legal values can only be /addresses/
of other objects" ?

The null pointer constant, mentioned above,
is a defined value for pointers, but is not an address.
The "one past" pointer, also has a legal value,
but does not point to an object.
 
I

Irrwahn Grausewitz

iirc, yes.

IIRC, no.

ISO/IEC 9899:TC1
3.14 object
region of data storage in the execution environment, the contents of
which can represent values. [...]

Functions, in this context, have no contents that can represent values.
<grin>
or even more convoluted, how about
"a pointer is an /object/ whose legal values can only be /addresses/
of other objects" ?

I'd rather say that pointer objects can hold pointer values. It
seems the terminus "pointer" is (IMHO unfortunaltely) often used
as a synonym for "pointer object" or "pointer value" respectively,
depending on context.

(Thanks, Ben Pfaff.)

Regards
 
S

Sheldon Simms

The null pointer constant, mentioned above,
is a defined value for pointers, but is not an address.
The "one past" pointer, also has a legal value,
but does not point to an object.

A null pointer constant is not a pointer at all. It first becomes a
(null) pointer after conversion to a pointer type.

-Sheldon
 
S

Sheldon Simms

That is precisely how I use it. I'm aware of this strange idea of "const
variable". I think it's easier and more useful to talk about objects.

The word variable comes to programming from mathematics, where it
is also possible to have a variable with a constant value.

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.

-Sheldon
 
R

Richard Heathfield

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

I challenge your assertion. Please provide evidence in support of it. In the
absence of such evidence, people will of course draw their own conclusions.
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.

But you yourself said this. If it's blabber, it's /your/ blabber.
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.

Of course. We all are, you included. So?
 
P

pete

Sheldon said:
A null pointer constant is not a pointer at all. It first becomes a
(null) pointer after conversion to a pointer type.

((void *)0) is a null pointer constant.
The type of ((void *)0), is pointer to void.

After this line of code:

char *pointer = (void *)0;

The value of pointer, is not an address.
The value of pointer is legal.
 
P

pete

Sheldon said:
The word variable comes to programming from mathematics, where it
is also possible to have a variable with a constant value.

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.

The same object, can represent different values,
with the same bit pattern, depending on the type of
the identifier used to access the object.

If you malloc a byte, for a pointer to void, called pointer,
and then make an assignment like
*(signed char*)pointer = -1;
then, an expression like
(*(unsigned char*)pointer)
would have a different value.
 
C

CBFalconer

Richard said:
I don't believe you. Please provide evidence to support that assertion.


Indeed it is, in common with several other of your recent articles. You
owe several people on this newsgroup an apology.

This is inane. Connor appears to be as un-educable as
Cunningham. I wonder if he and Roose have gotten together in some
manner to stir up the ant-hill called c.l.c. They don't appear to
be the same person. Will this get me on his plonk list?
 
K

Keith Thompson

Irrwahn Grausewitz said:
Err, damn, no, neither! I managed to forget to mention the name of the
individual in question: Alan Conor.
Did you ever abuse usenet in a manner that would make it worth to do a
google search? Can't imagine that. :)

No, I don't think so. Searching for my own name is somewhat
interesting to me, but probably not to anyone else.
 
K

Keith Thompson

Sheldon Simms said:
A null pointer constant is not a pointer at all. It first becomes a
(null) pointer after conversion to a pointer type.

A null pointer constant is a syntactic entity, a construct in C source
code. A null pointer is a value that can exist at run time. They
have much the same relationship as an identifier and an object, or the
consecutive characters '4' and '2' in your foo.c file and the bits
representing the integer 42 in your running program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,303
Messages
2,571,557
Members
48,359
Latest member
Raqib_121635
Top