473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Please check the content of my web page on 'A note on Pointer Operation'

It is at http://211.30.198.135/pointer_operations.html. I want to get this reviewed to make sure that they are correct.

I'm not sure whether copy/paste will show up correctly but the content is:

A note on Pointer Operation

We start with the table:
Object Address
xp &xp
*p p

Table 1.

We can illustrate the relationship contained in the table clearer if we also visit the table:
Object Address Object Address
xp &xp *p p
*p p xp &xp

Table 2.

We can gather from this the following assignments:

xp=*p; &xp=p;

*p=xp; p=&xp;

We can immediately see from this that the relationship is commutative, namely that xp=*p and *p=xp or that &xp=p and p=&xp.

Also it occurs that &xp=&*p=p and &*p=&xp=p. Basically it is saying that &*p=p. What about *&xp? Yes, similarly we deduce that *&xp=*p=xp and *p=*&xp=xp, which means *&xp=xp. So we confirm that &xp=p and *p=xp.

Lastly, it also occurs that the operation &* is equivalent to *&.
Dec 16 '07 #1
11 1498
Logan Lee <Lo*********@student.uts.edu.auwrites:
It is at http://211.30.198.135/pointer_operations.html. I want to get this reviewed to make sure that they are correct.

I'm not sure whether copy/paste will show up correctly but the content is:

A note on Pointer Operation

We start with the table:
Object Address
xp &xp
*p p

Table 1.

We can illustrate the relationship contained in the table clearer if we also visit the table:
Object Address Object Address
xp &xp *p p
*p p xp &xp

Table 2.

We can gather from this the following assignments:
^^^^^^^^^^^
I'm not sure about the approriateness of the word 'assignments' here and also whether I should really write A==B rather than A=B.
>
xp=*p; &xp=p;

*p=xp; p=&xp;

We can immediately see from this that the relationship is commutative, namely that xp=*p and *p=xp or that &xp=p and p=&xp.

Also it occurs that &xp=&*p=p and &*p=&xp=p. Basically it is saying that &*p=p. What about *&xp? Yes, similarly we deduce that *&xp=*p=xp and *p=*&xp=xp, which means *&xp=xp. So we confirm that &xp=p and *p=xp.

Lastly, it also occurs that the operation &* is equivalent to *&.
Dec 16 '07 #2
Logan Lee <Lo*********@student.uts.edu.auwrites:
It is at http://211.30.198.135/pointer_operations.html. I want to get this reviewed to make sure that they are correct.

I'm not sure whether copy/paste will show up correctly but the content is:

A note on Pointer Operation

We start with the table:
Object Address
xp &xp
*p p

Table 1.

We can illustrate the relationship contained in the table clearer if we also visit the table:
Object Address Object Address
xp &xp *p p
*p p xp &xp

Table 2.

We can gather from this the following assignments:

xp=*p; &xp=p;

*p=xp; p=&xp;

We can immediately see from this that the relationship is commutative, namely that xp=*p and *p=xp or that &xp=p and p=&xp.

Also it occurs that &xp=&*p=p and &*p=&xp=p. Basically it is saying that &*p=p. What about *&xp? Yes, similarly we deduce that *&xp=*p=xp and *p=*&xp=xp, which means *&xp=xp. So we confirm that &xp=p and *p=xp.

Lastly, it also occurs that the operation &* is equivalent to *&.
I can't set up apache very well so I put the stuff up on http://www.geocities.com/logan.lee30...perations.html.
Dec 16 '07 #3
On Dec 16, 1:55 am, Logan Lee <Logan.W....@student.uts.edu.auwrote:
>
Lastly, it also occurs that the operation &* is equivalent to *&.
In an academic sense, that may be true, but you need to be careful.
Consider:

char c = 'c';
'c' == *&c; /* okay */
'c' == &*c; /* error */

IOW, if you think of * and & as operators on the
appropriate space, then &* and *& are equivalent.
However, in an actual implementation, it aint so,
since the actual domains/codomains don't match.

Think of * as an operator on the space of all
objects of type pointer, and & as an operator
on the space of all objects. Clearly, *c
is undefined if c is not a pointer, so *&c
will be defined as long as c is an object,
but &*c is only defined if c is an object
of type pointer.
Dec 16 '07 #4
William Pursell <bi**********@gmail.comwrites:
>>Clearly, *c
is undefined if c is not a pointer, so *&c
will be defined as long as c is an object,
but &*c is only defined if c is an object
of type pointer.
OK.
Dec 16 '07 #5
William Pursell wrote:
On Dec 16, 1:55 am, Logan Lee <Logan.W....@student.uts.edu.auwrote:
>Lastly, it also occurs that the operation &* is equivalent to *&.

In an academic sense, that may be true, but you need to be careful.
Consider:

char c = 'c';
'c' == *&c; /* okay */
'c' == &*c; /* error */

IOW, if you think of * and & as operators on the
appropriate space, then &* and *& are equivalent.
However, in an actual implementation, it aint so,
since the actual domains/codomains don't match.

Think of * as an operator on the space of all
objects of type pointer,
values of type pointer. It doesn't have to be an object.
For example *(p + i) which is the same as the familiar p[i].

So another counterexample is the following:

char c = 'c';
char *pc = &c;
pc == &*&c; /* okay */
pc == *&&c; /* error */

....which shows that &* is sometimes valid when *& isn't.
and & as an operator
on the space of all objects. Clearly, *c
is undefined if c is not a pointer, so *&c
will be defined as long as c is an object,
but &*c is only defined if c is an object
of type pointer.
Dec 16 '07 #6
Logan Lee wrote:
Logan Lee <Lo*********@student.uts.edu.auwrites:
>We can gather from this the following assignments:
^^^^^^^^^^^
I'm not sure about the approriateness of the word 'assignments' here and also whether I should really write A==B rather than A=B.
I would agree entirely here. "Equalities" is probably a better word.
Dec 16 '07 #7
Logan Lee wrote:
>>
We can gather from this the following assignments:
^^^^^^^^^^^
I'm not sure about the approriateness of the word 'assignments' here and also whether I should really write A==B rather than A=B.
Assignments is correct.

double equals is very definitely wrong - thats the logical "is equal to"
operator, not the assignment operator.
Dec 16 '07 #8
On Dec 16, 10:22 am, Philip Potter <p...@doc.ic.ac.ukwrote:
William Pursell wrote:
On Dec 16, 1:55 am, Logan Lee <Logan.W....@student.uts.edu.auwrote:
Lastly, it also occurs that the operation &* is equivalent to *&.
In an academic sense, that may be true, but you need to be careful.
Consider:
char c = 'c';
'c' == *&c; /* okay */
'c' == &*c; /* error */
IOW, if you think of * and & as operators on the
appropriate space, then &* and *& are equivalent.
However, in an actual implementation, it aint so,
since the actual domains/codomains don't match.
Think of * as an operator on the space of all
objects of type pointer,

values of type pointer. It doesn't have to be an object.
For example *(p + i) which is the same as the familiar p[i].

So another counterexample is the following:

char c = 'c';
char *pc = &c;
pc == &*&c; /* okay */
pc == *&&c; /* error */

...which shows that &* is sometimes valid when *& isn't.
Is &* evident in that counterexample? The first
line is an example of the '&' operator being applied
to the result of *&c, while the second is in error
because of the '&&' construct. I am very confused,
however, about the following diagnostic:

$ cat a.c
#include <stdio.h>

int
main( void )
{
char c = 'c';
char **d;

d = &&c; /* Bogus code for demonstration.*/

return 0;
}

$ gcc a.c
a.c: In function 'main':
a.c:9: error: label 'c' used but not defined

Is this a gcc oddity?
Dec 16 '07 #9
William wrote:
) $ gcc a.c
) a.c: In function 'main':
) a.c:9: error: label 'c' used but not defined
)
) Is this a gcc oddity?

Probably. Since '&&' is an illegal construct in standard C, it can be used
as an extension. I would assume that in this case, '&&' operates on labels.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Dec 16 '07 #10
Mark McIntyre wrote:
Logan Lee wrote:
>>We can gather from this the following assignments:
^^^^^^^^^^^
I'm not sure about the approriateness of the word 'assignments' here and also whether I should really write A==B rather than A=B.

Assignments is correct.

double equals is very definitely wrong - thats the logical "is equal to"
operator, not the assignment operator.
Assignments describes the = operator correctly, but the = operator was
used wrongly in the original context. After making a statement, the OP
said "We can gather from this the following assignments" and suggested
that "the relationship is commutative" - suggesting that he was looking
at equalities in the code, rather than assignments, which are not
commutative.

Actually, looking at the OP again, he suggests that xp==*p without any
previous reference to a relationship between xp and p. This is not the
case. He should have first said p = &xp; although without stating the
type of p and xp it is not clear that this assignment is possible.

Philip
Dec 16 '07 #11
William Pursell wrote:
On Dec 16, 10:22 am, Philip Potter <p...@doc.ic.ac.ukwrote:
>William Pursell wrote:
>>On Dec 16, 1:55 am, Logan Lee <Logan.W....@student.uts.edu.auwrote:
Lastly, it also occurs that the operation &* is equivalent to *&.
In an academic sense, that may be true, but you need to be careful.
Consider:
char c = 'c';
'c' == *&c; /* okay */
'c' == &*c; /* error */
IOW, if you think of * and & as operators on the
appropriate space, then &* and *& are equivalent.
However, in an actual implementation, it aint so,
since the actual domains/codomains don't match.
Think of * as an operator on the space of all
objects of type pointer,
values of type pointer. It doesn't have to be an object.
For example *(p + i) which is the same as the familiar p[i].

So another counterexample is the following:

char c = 'c';
char *pc = &c;
pc == &*&c; /* okay */
pc == *&&c; /* error */

...which shows that &* is sometimes valid when *& isn't.

Is &* evident in that counterexample? The first
line is an example of the '&' operator being applied
to the result of *&c, while the second is in error
because of the '&&' construct.
Replace '&c' with any pointer value with no address:

register char *c;
&*c; /* okay [1] */
*&c; /* error */

Philip

[1] and even though this looks like it dereferences an uninitialized
pointer, which is a Bad Thing, this particular example is defined
behaviour due to the special case in 6.5.3.2p3.
Dec 16 '07 #12

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

Similar topics

7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: Stephajn Craig | last post by:
I have one page that may take a while to process on the server, and I'd like to implement a please wait message on this page when it posts back to the server and does its business. The page is...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
by: albert_reade | last post by:
Hello I was wondering if someone could please help me understand what I need to do in order to get this project to work. I just need some hints or a push in the right direction to get this to work,...
0
by: raa abdullah | last post by:
Overview A conflict-serializbility\recoverability checker, SCR, is a program that takes in a schedule and outputs 2 decisions: Conflict serialzable or Not confilict serializable AND Recoverable or...
9
by: webrod | last post by:
Hi all, how can I check a user/password in a LDAP ? I don't want to connect with this user, I would like to connect to LDAP with a ADMIN_LOG/ADMIN_PWD, then do a query to find the user and...
1
by: td0g03 | last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
30
by: Alf P. Steinbach | last post by:
I once suggested in that SomeOne Else(TM) should propose a string value class that accepted literals and char pointers and so on, with possible custom deleter, and in case of literal strings just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.