473,624 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updates to Pointer Guide

http://thelinuxlink.net/~fingolfin/pointer-guide/

I've made a lot of corrections, and put in more new stuff. I have
malloc and pointers to struct's and maybe a few more things and I'm
done.

Examine it and tell me what you think.
Nov 14 '05 #1
2 1541

On Mon, 2 Aug 2004, Arthur J. O'Dwyer wrote:

[Copied to myself since I can't tell for sure whether that's
a real email address or a much-too-cute fake one in your From
header]
Apparently it's a too-cute fake one. Please change it to a
more obviously munged one, or one that's not munged at all.

On Sun, 1 Aug 2004, Foobarius Frobinium wrote:

http://thelinuxlink.net/~fingolfin/pointer-guide/
Examine it and tell me what you think.


...the addresss of each member...
s/addresss/address/
and similar spell-checking throughout.

...syntax sugar...
s/syntax/syntactic/

...foo[2] is nearly identical to *(foo + 2). The interchangabili ty...
s/is nearly identical to/has the same effect as/
s/interchangabili ty/interchangeabil ity/
unless it really is spelled that way in British English, but I
doubt it.

...single-dimension arrays...
s/single-dimension/one-dimensional/

You might consider changing the array values in the example that
uses the code
fprintf(stdout, "%i\n", *bar);
fprintf(stdout, "%i\n", *(bar + 1));
fprintf(stdout, "%i\n", *(bar + 2));
so that *(bar + 1) evaluates to a different value from (*bar + 1),
and so on. Especially since you made a big deal about the
difference earlier in the tutorial.

Is there a reason you're using 'fprintf(stdout , ...' instead of
'printf(...'? It looks a lot like needless complexity to me.

...So, instead, I must type &baz[0][0]...
You could just as well have typed 'baz[0]'. The ampersand cancels
out the dereference. Did you mention this already? It's a very
important and useful fact.

In fact, you never mention the word 'sizeof' in the entire
tutorial --- did you ever mention that while 'sizeof(int)' is
/not/ always 2, 'sizeof(char)' /is/ always 1? That's important.

By the time we get to "True Pointers to Arrays," you should be
using the array notation exclusively. '*(bar + 1)' should be
'bar[1]' from here on out; and so on.

...array of char's... ...array of int's...
Suggest "array of char", where "char" is set in a fixed-width
font, and so on. Either that, or reword the sentence
"We are aware that an array's name will always decay into a pointer to its
first element. In the case, for example, of an array of char's..."
The two apostrophes are too close together for comfort.
Similar complaints re: "an array of char's that is seven long."
The plural of "char" ought to be "chars," no matter how you decide
to format it; and the use of the type-name 'long' in this context
might confuse the reader. Formatting type-names in fixed-width font
would solve the latter problem.

Suggest placing comments in code examples which invoke undefined
behavior, for example

fprintf(stdout, "%s\n", *(bar + 2));

ought to read

printf("%s\n", bar[2]); /* ERROR! */

...pointers to arrays with a three dimensional array...
s/arrays/arrays,/
s/three dimensional/three-dimensional/

...If this confuses you, that's OK. There are very, very few people
whom it would not confuse at first glance...
Save the cute comments for the stuff that's /really/ difficult to
understand, not the stuff that's just poorly written. Making the
substitutions already discussed, and reflowing the array declaration
to mirror its actual use, we have

#include <stdio.h>

void foo(int (*bar)[3][4]);

int main(void)
{
int baz[][3][4] = {
{
{ 0, 1, 2, 3 },
{ 4, 5, 6, 7 },
{ 8, 9, 10, 11 }
}, {
{ 12, 13, 14, 15 },
{ 16, 17, 18, 19 },
{ 20, 21, 22, 23 }
}
};

foo(baz);
return 0;
}

void foo(int (*bar)[3][4])
{
int (*buzz)[4] = bar[1];
printf("%i\n", buzz[2][2]);
}

I don't think this should confuse anyone, except perhaps over the
relative precedence of * and [] in the function prototype declaration
of 'bar'. In fact, it might be better to write

void foo(int bar[][3][4]);

so as to make the parallel clearer. However, you do make a point of
explaining what's going on with '(*bar)[3][4]'; that's good.

The accompanying "Address/Value" table is more than a screen long.
Consider breaking it into multiple columns.

...bash, a CLI command interpreter...
The usual term is "shell." And you never explain what the acronym
"CLI" means --- I wouldn't expect a naive user to know what "CLI"
meant and yet not recognize the term "bash" from context.

...This is what prints... ...indpedence.. .
No, it isn't.

Your last sample program does not #include <string.h>, which is
a fatal error. And 'strlen' is defined in exactly the same way
on all systems; there's no reason to qualify your sentence with
"...on my system".
There are more typos and stylistic problems, but a good English-
language proofreader (I would think preferably one who's /not/ a
C expert) can catch those. These are most of the critical errors
that I saw.

HTH,
-Arthur

Nov 14 '05 #2
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote in message news:<Pi******* *************** ************@un ix48.andrew.cmu .edu>...
On Mon, 2 Aug 2004, Arthur J. O'Dwyer wrote:

[Copied to myself since I can't tell for sure whether that's
a real email address or a much-too-cute fake one in your From
header]
Well, fingolfin AT thelinuxlink DOT net is the real one. P.S. I added
a special thanks section with your name on it. Very useful criticisms
here.
On Sun, 1 Aug 2004, Foobarius Frobinium wrote:

http://thelinuxlink.net/~fingolfin/pointer-guide/
Examine it and tell me what you think.


...the addresss of each member...
s/addresss/address/
and similar spell-checking throughout.
Done. Used ispell. :)

...syntax sugar...
s/syntax/syntactic/
Done.

...foo[2] is nearly identical to *(foo + 2). The interchangabili ty...
s/is nearly identical to/has the same effect as/
s/interchangabili ty/interchangeabil ity/
unless it really is spelled that way in British English, but I
doubt it.
I'm not British. Of British descent...but not British.

...single-dimension arrays...
s/single-dimension/one-dimensional/
Done.

You might consider changing the array values in the example that
uses the code
fprintf(stdout, "%i\n", *bar);
fprintf(stdout, "%i\n", *(bar + 1));
fprintf(stdout, "%i\n", *(bar + 2));
so that *(bar + 1) evaluates to a different value from (*bar + 1),
and so on. Especially since you made a big deal about the
difference earlier in the tutorial.
Hm. I am redundant in the guide. But I think one instance would be
good enough in this case.

Is there a reason you're using 'fprintf(stdout , ...' instead of
'printf(...'? It looks a lot like needless complexity to me.
A convention I picked up off of esr's earlier code.

...So, instead, I must type &baz[0][0]...
You could just as well have typed 'baz[0]'. The ampersand cancels
out the dereference. Did you mention this already? It's a very
important and useful fact.
Yes...but here's the problem: my explanation does not make sense until
later in the guide. This would use the 'double decay' effect if I am
not mistaken, yes?

1) baz decays into a pointer to its first element, an array of char,
of seven members
2) The pointer is dereferenced.
3) The resulting array decays once more.

In fact, you never mention the word 'sizeof' in the entire
tutorial --- did you ever mention that while 'sizeof(int)' is
/not/ always 2, 'sizeof(char)' /is/ always 1? That's important.
I will get to sizeof in malloc section. I did not know different
architectures have different int sizes.

By the time we get to "True Pointers to Arrays," you should be
using the array notation exclusively. '*(bar + 1)' should be
'bar[1]' from here on out; and so on.
Hm...I want to at least get people aware of the other, less popular
notation. But I will probably make some changes according to that
criticism

...array of char's... ...array of int's...
Suggest "array of char", where "char" is set in a fixed-width
font, and so on. Either that, or reword the sentence
"We are aware that an array's name will always decay into a pointer to its
first element. In the case, for example, of an array of char's..."
The two apostrophes are too close together for comfort.
Similar complaints re: "an array of char's that is seven long."
The plural of "char" ought to be "chars," no matter how you decide
to format it; and the use of the type-name 'long' in this context
might confuse the reader. Formatting type-names in fixed-width font
would solve the latter problem.
I see. I spent some time doing this as well.

Suggest placing comments in code examples which invoke undefined
behavior, for example

fprintf(stdout, "%s\n", *(bar + 2));

ought to read

printf("%s\n", bar[2]); /* ERROR! */
Done.

...pointers to arrays with a three dimensional array...
s/arrays/arrays,/
s/three dimensional/three-dimensional/
Done.

...If this confuses you, that's OK. There are very, very few people
whom it would not confuse at first glance...
Save the cute comments for the stuff that's /really/ difficult to
understand, not the stuff that's just poorly written. Making the
substitutions already discussed, and reflowing the array declaration
to mirror its actual use, we have
<snip>

I'll probably put something like that in there. Again, I did want to
show the unpopular method just to make sure no one confuses pointers
and arrays.

...This is what prints... ...indpedence.. .
No, it isn't.
Changed.

Your last sample program does not #include <string.h>, which is
a fatal error. And 'strlen' is defined in exactly the same way
on all systems; there's no reason to qualify your sentence with
"...on my system".
Changed.


There are more typos and stylistic problems, but a good English-
language proofreader (I would think preferably one who's /not/ a
C expert) can catch those. These are most of the critical errors
that I saw.

HTH,
-Arthur


Thx
Nov 14 '05 #3

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

Similar topics

4
1945
by: hari4063 | last post by:
Hay, I decalre pointer-to-member and it's sizeof iz 12 (in Borland 5) or 4 (in MinGW)? When I debugged code, only parameters pushed on stack is 'this' and call was indirect? What other 2 dwords are?
40
1833
by: Foobarius Frobinium | last post by:
Please review this guide for clarity, accuracy, etc. so I can hopefully compile a very good tutorial on how to use pointers in C, including advanced topics, that is easy to follow and exposes the details. http://thelinuxlink.net/~fingolfin/pointer-guide/ My e-mail address is fake. To really contact me, send mail to: fingolfinJOHNLENNONSPENIS@thelinuxlink.net, subtracting the blatant anti-spam component.
2
1200
by: Foobarius Frobinium | last post by:
Still not complete, as I need a cycle of feedback to be successful, but much improved. After corrections, I won't have much more to do. http://thelinuxlink.net/~fingolfin/pointer-guide/ Check out stuff on the main site as well if you wish...
48
2367
by: Foobarius Frobinium | last post by:
http://thelinuxlink.net/~fingolfin/pointer-guide Tell me what you think...
0
8240
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8175
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8482
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6111
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.