473,408 Members | 1,861 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,408 software developers and data experts.

Question on Pointer Indirections

rs
Just out of idle curiosity:

1)Regarding pointers; I don't have the standard/grammar with me, but T* for
type T mean pointer-to-T. Does that mean that with a declaration of type
T** is actually a pointer to a type pointer, T*** is a pointer to type
pointer to type pointer and so on?

2) Is there any history behind the use of the "*" operator in providing
dereferencing capabilities or is it arbitrary? How did B handle pointers?
(if it had any). I'm specifically interested in why K&R didn't just
introduce a set of keywords for memory refrencing/derefrencing

3) [OT - But I would appreciate an ans if you have one] C++ has the
reference operator, which, in my limited experience is just a convenient way
of doing pointers; is this so? Is there any major difference in the
semantics or am I right?

4)Is there any practical use for pointers of more than 2 levels of
indireciton? i can't think of any. If this is the case would anything have
been gained (I guess apart from slight grammar simplification and compiler
implementation simplicity) from introducing T** and leaving it at that?

Thanks
Nov 14 '05 #1
7 1398
On Thu, 19 Feb 2004 03:28:59 -0000, "rs" <no************@talk21.com>
wrote in comp.lang.c:
Just out of idle curiosity:

1)Regarding pointers; I don't have the standard/grammar with me, but T* for
type T mean pointer-to-T. Does that mean that with a declaration of type
T** is actually a pointer to a type pointer, T*** is a pointer to type
pointer to type pointer and so on?
Yes.
2) Is there any history behind the use of the "*" operator in providing
dereferencing capabilities or is it arbitrary? How did B handle pointers?
(if it had any). I'm specifically interested in why K&R didn't just
introduce a set of keywords for memory refrencing/derefrencing
Pass.
3) [OT - But I would appreciate an ans if you have one] C++ has the
reference operator, which, in my limited experience is just a convenient way
of doing pointers; is this so? Is there any major difference in the
semantics or am I right?
comp.lang.c++ is down the hall to the right. The differences between
pointers and references are topical there.
4)Is there any practical use for pointers of more than 2 levels of
indireciton? i can't think of any. If this is the case would anything have
been gained (I guess apart from slight grammar simplification and compiler
implementation simplicity) from introducing T** and leaving it at that?
Yes, sometimes.
Thanks


--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
in comp.lang.c i read:
1)Regarding pointers; I don't have the standard/grammar with me, but T* for
type T mean pointer-to-T. Does that mean that with a declaration of type
T** is actually a pointer to a type pointer, T*** is a pointer to type
pointer to type pointer and so on?
yes.
2) Is there any history behind the use of the "*" operator in providing
dereferencing capabilities or is it arbitrary? How did B handle pointers?
(if it had any). I'm specifically interested in why K&R didn't just
introduce a set of keywords for memory refrencing/derefrencing
i have dim memories of this, iirc it was because it was terse and apropos
(usage follows definition).
3) [OT - But I would appreciate an ans if you have one] C++ has ...
sorry, that would just encourage other off-topicness. the people in
comp.lang.c++ can respond.
4)Is there any practical use for pointers of more than 2 levels of
indireciton? i can't think of any.


if you have a T** and you want to pass the object (not any of the referents
nor a copy) to a function (so the function can change it) then you need a
T***, and if that function ...

also, in c multidimensional arrays are actually arrays of arrays.

--
a signature
Nov 14 '05 #3
rs wrote:
1)Regarding pointers; I don't have the standard/grammar with me,
but T* for type T mean pointer-to-T.
Does that mean that with a declaration of type T**
is actually a pointer to a type pointer,
T*** is a pointer to type pointer to type pointer and so on?
Yes.
2) Is there any history behind the use of the "*" operator
in providing dereferencing capabilities or is it arbitrary?
It is arbitrary but I'm sure that K&R carefully considered the choices.
I'm specifically interested in why K&R didn't just introduce
a set of keywords for memory referencing/dereferencing.
Like the sizeof operator?
I think that their objective was simply to be concise.
Teletype was still popular when K&R were designing C.
They were probably just trying to minimize the number of keystrokes
that programmers would be obliged to type so they exploited
the punctuation available on an ASCII keyboard.
3) [OT - But I would appreciate an answer if you have one]
C++ has the reference operator which, in my limited experience,
is just a convenient way of doing pointers; Is this so?
Is there any major difference in the semantics or am I right?
A pointer is an object which contains the address of another object.
A reference is just another name for an object.
In the C computer programming language,

const char* p = "qwerty";

p is a *pointer* to a character with [constant] value 'q' and
*p is a *reference* to that character.
4)Is there any practical use
for pointers of more than 2 levels of indirection?
Rarely.
If this is the case,
would anything have been gained (I guess apart from
slight grammar simplification and compiler implementation simplicity)
from introducing T** and leaving it at that?


No.
Limiting the levels of indirection would probably just make the grammar
less comprehensible and the compiler more complicated.

Nov 14 '05 #4
rs wrote:
4)Is there any practical use for pointers of more than 2 levels of
indireciton?
Yes.
i can't think of any.
Doesn't mean there aren't any.
If this is the case would anything
have been gained (I guess apart from slight grammar simplification and
compiler implementation simplicity) from introducing T** and leaving it at
that?


Well, let's just see if T** is adequate, first. Let's resize a dynamically
allocated array of chars:

#include <stdlib.h>
int resize_string(char **s, size_t *oldlen, size_t newlen)
{
int rc = 1; /* assume failure */
char *t = realloc(*s, newlen);
if(t != NULL)
{
*s = t;
*oldlen = newlen;
rc = 0; /* it worked */
}
return rc;
}

So okay, T ** is adequate for resizing a string.

Now I want to resize a dynamically-allocated array of dynamically-allocated
strings:

int resize_string_array(char *** Oops, not allowed three stars in this
version of C.

--
Richard Heathfield : bi****@eton.powernet.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 14 '05 #5
E. Robert Tisdale wrote:

rs wrote:
[ snip ]
2) Is there any history behind the use of the "*" operator
in providing dereferencing capabilities or is it arbitrary?


It is arbitrary but I'm sure that K&R carefully considered the choices.

K&R didn't write C. R did.
I'm specifically interested in why K&R didn't just introduce
a set of keywords for memory referencing/dereferencing.


Like the sizeof operator?
I think that their objective was simply to be concise.
Teletype was still popular when K&R were designing C.


Again, Dennis Ritchie designed C. Brian Kernighan was the author of the
book, not the co-designer of the language.
They were probably just trying to minimize the number of keystrokes
that programmers would be obliged to type so they exploited
the punctuation available on an ASCII keyboard.
3) [OT - But I would appreciate an answer if you have one]
C++ has the reference operator which, in my limited experience,
is just a convenient way of doing pointers; Is this so?
Is there any major difference in the semantics or am I right?
A pointer is an object which contains the address of another object.


Yes.
A reference is just another name for an object.
Absolutely not!
In the C computer programming language,

const char* p = "qwerty";

p is a *pointer* to a character with [constant] value 'q' and
*p is a *reference* to that character.

No. C has no 'reference' at all except as you may use the English word
as 'refers to' or somesuch. In C++ and other languages, 'pass by
reference' infers semantics and operations that simply can't be done in
C.
4)Is there any practical use
for pointers of more than 2 levels of indirection?


Rarely.
If this is the case,
would anything have been gained (I guess apart from
slight grammar simplification and compiler implementation simplicity)
from introducing T** and leaving it at that?


No.
Limiting the levels of indirection would probably just make the grammar
less comprehensible and the compiler more complicated.


--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #6
Groovy hepcat E. Robert Tisdale was jivin' on Wed, 18 Feb 2004
21:07:58 -0800 in comp.lang.c.
Re: Question on Pointer Indirections's a cool scene! Dig it!
rs wrote:
3) [OT - But I would appreciate an answer if you have one]
C++ has the reference operator which, in my limited experience,
is just a convenient way of doing pointers; Is this so?
Is there any major difference in the semantics or am I right?


A pointer is an object which contains the address of another object.
A reference is just another name for an object.
In the C computer programming language,

const char* p = "qwerty";

p is a *pointer* to a character with [constant] value 'q' and
*p is a *reference* to that character.


Wrong! References in C: there ain't no sech animal. References are a
feature of C++.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
Nov 14 '05 #7
On Thu, 19 Feb 2004 03:28:59 -0000, "rs" <no************@talk21.com>
wrote:
Just out of idle curiosity:

1)Regarding pointers; I don't have the standard/grammar with me, but T* for
type T mean pointer-to-T. Does that mean that with a declaration of type
T** is actually a pointer to a type pointer, T*** is a pointer to type
pointer to type pointer and so on?
Yes, but not quite. As an *abstract declarator* (used in a cast, or
sizeof, or a nondefining prototype declaration that chooses to omit
parameter names) it *is* such a type, yes. In a declaration the
asterisks parse as part of the declarator, not of the type-specifiers,
so T** x where x is a simple identifier declares x a pointer to
pointer to T, but for example T ** x(whatever) declares as *function
returning* pointer to pointer to T; effectively the result is as if
T** were (part of) the type but the syntax doesn't treat it that way.
2) Is there any history behind the use of the "*" operator in providing
dereferencing capabilities or is it arbitrary? How did B handle pointers?
(if it had any). I'm specifically interested in why K&R didn't just
introduce a set of keywords for memory refrencing/derefrencing
According to http://cm.bell-labs.com/cm/cs/who/dmr/chist.html B did
use *; this, like other syntax changes between BCPL and B, seems to be
arbitrary; certainly dmr doesn't present any rationale.

B and BCPL did have pointers, but just (typeless) integers treated as
addresses of equally typeless cells; they don't have stride or target
information as in C, and most other HLLs that have pointers at all.
4)Is there any practical use for pointers of more than 2 levels of
indireciton? i can't think of any. If this is the case would anything have
been gained (I guess apart from slight grammar simplification and compiler
implementation simplicity) from introducing T** and leaving it at that?

In programming, the counting system is very often [zero,] one, many.
Once you go to the trouble of doing two it is often as easy to do
several, and as noted elsethread *simpler* formally because you just
recurse rather than enumerating cases. And for pointers it is
sometimes useful, though much less often than 1 and 2.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #8

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

Similar topics

20
by: __PPS__ | last post by:
Hello everybody in a quiz I had a question about dangling pointer: "What a dangling pointer is and the danger of using it" My answer was: "dangling pointer is a pointer that points to some...
7
by: Michael Birkmose | last post by:
Hi everyone!, Are pointers to incomplete types allowed in ANSI C? I can see that pointer arithmic on pointers to incomple types is impossible, however there are situations where it can be...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
0
by: Christopher Sin | last post by:
Hi, First, if I am on a wrong group, please tell me, therefore, i think this one is correct. Second, please ignore my poor English speaking. I have to write a c# wrapper to a C library....
11
by: Fred | last post by:
Hi I'm new to the std library. I have a function which reads data and creates a std string from it. I want to pass that back to the calling function as a parameter, not as the function return. ...
7
by: Jake Thompson | last post by:
Hello I have the following defined structure struct cm8linkstruc { char *type; /* type of item*/ char *desc; /* description of item ...
14
by: Brian | last post by:
Hello - I have been told that for extra efficiency we should always compile code with frame pointer ommited (-fomit-frame-pointer), also -pipe. What is the reason for this? Why does it make a...
30
by: none | last post by:
I'm trying to overload the = operator using templates, but I have some problems with one of the overloads, I would like to make something like that: intvariable = fooclass; here's a pseudo...
2
by: Giorgos Keramidas | last post by:
On Sun, 05 Oct 2008 18:22:13 +0300, Giorgos Keramidas <keramida@ceid.upatras.grwrote: My apologies. I should have been less hasty to hit `post'. If showtext() is passed a null pointer, it may...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.