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

Your view of FAQ section.


One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?

e.g

,----
| It is useful to realize that a reference like x[3] generates different code depending on whether x is an array or a pointer. Given the declarations above, when the compiler
| sees the expression a[3], it emits code to start at the location ``a'', move three past it, and fetch the character there. When it sees the expression p[3], it emits code to
| start at the location ``p'', fetch the pointer value there, add three to the pointer, and finally fetch the character pointed to. In other words, a[3] is three places past
| (the start of) the object named a, while p[3] is three places past the object pointed to by p. In the example above, both a[3] and p[3] happen to be the character 'l', but
| the compiler gets there differently. (The essential difference is that the values of an array like a and a pointer like p are computed differently whenever they appear in
| expressions, whether or not they are being subscripted, as explained further in question 6.3.) See also question 1.32.
`----

Jun 2 '07 #1
12 1172
Richard <rg****@gmail.comwrites:
One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?
Yes.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 2 '07 #2
Keith Thompson <ks***@mib.orgwrites:
Richard <rg****@gmail.comwrites:
>One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?

Yes.
Can you explain why?

Does the standard stipulate how the compiler must generate the addresses?
Jun 3 '07 #3
Richard <rg****@gmail.comwrites:
Keith Thompson <ks***@mib.orgwrites:
>Richard <rg****@gmail.comwrites:
>>One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?

Yes.

Can you explain why?

Does the standard stipulate how the compiler must generate the addresses?
Ok, that was overly terse. But the FAQ doesn't really talk about
generated code; it's more of a description of what happens in the
abstract machine, which is important to an understanding of what the
code actually means.

Do you have a better way to describe the difference between a[3] and
p[3] (where a is an array object and p is a pointer object)?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 3 '07 #4

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Richard <rg****@gmail.comwrites:
>Keith Thompson <ks***@mib.orgwrites:
>>Richard <rg****@gmail.comwrites:
One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?

Yes.

Can you explain why?

Does the standard stipulate how the compiler must generate the addresses?

Ok, that was overly terse. But the FAQ doesn't really talk about
generated code; it's more of a description of what happens in the
abstract machine, which is important to an understanding of what the
code actually means.

Do you have a better way to describe the difference between a[3] and
p[3] (where a is an array object and p is a pointer object)?
Exactly. People are looking for an explanation, not a definition. Sometimes
it is better to say something which is slightly inaccurate, or only
represents the general case, but is concrete, rather than give the latter of
the law.

Array - pointer equivalance is a classic case. Unless you go through a
stage of thinking that arrays and pointers are equivalent, you will never
understand why they are not equivalent.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 3 '07 #5
Keith Thompson <ks***@mib.orgwrites:
Richard <rg****@gmail.comwrites:
>Keith Thompson <ks***@mib.orgwrites:
>>Richard <rg****@gmail.comwrites:
One of the most repeatedly given pointers is to

http://c-faq.com/aryptr/aryptr2.html

which discusses pointers and arrays and the subtle differences between

char a[] = "hello";
char *p = "world";

Now, my question is this - how do you feel about the way the FAQ
describes the compiler working. We already now that pointers and arrays
may or may not compile differently and may or may not be more efficient
than each other depending on target HW.

But should the FAQ really go into detail about how the compiler
calculates element addresses?

Yes.

Can you explain why?

Does the standard stipulate how the compiler must generate the addresses?

Ok, that was overly terse. But the FAQ doesn't really talk about
generated code; it's more of a description of what happens in the
abstract machine, which is important to an understanding of what the
code actually means.

Do you have a better way to describe the difference between a[3] and
p[3] (where a is an array object and p is a pointer object)?
No. But telling us how the compiler may or may not do it is overly
presumptuous IMO.

Only a while ago I was sure (as stated in K&R2 too btw) that using
pointers and not arrays generated faster code as a general rule. Some
work I have done since has pretty much made me change my mind.
Jun 3 '07 #6
Richard wrote:
Keith Thompson <ks***@mib.orgwrites:
>>
Do you have a better way to describe the difference between a[3] and
p[3] (where a is an array object and p is a pointer object)?

No. But telling us how the compiler may or may not do it is overly
presumptuous IMO.
The goal of the FAQ is explanation, not specification.
As such, it quite frequently ventures outside the territory
marked off by the Standard -- for example, it talks not only
about "undefined behavior" but also about "segmentation
violation" and "general protection fault." I see nothing
amiss with the FAQ speaking about generated code (which itself
is beyond the scope of the Standard) to highlight a point and
bring the reader closer to the "Aha!" moment.

--
Eric Sosman
es*****@acm-dot-org.invalid
Jun 3 '07 #7
Malcolm McLean wrote, On 03/06/07 10:17:
>
"Keith Thompson" <ks***@mib.orgwrote in message
<snip>
>Do you have a better way to describe the difference between a[3] and
p[3] (where a is an array object and p is a pointer object)?
Exactly. People are looking for an explanation, not a definition.
Sometimes it is better to say something which is slightly inaccurate, or
only represents the general case, but is concrete, rather than give the
latter of the law.
To an extent, yes.
Array - pointer equivalance is a classic case. Unless you go through a
stage of thinking that arrays and pointers are equivalent, you will
never understand why they are not equivalent.
However here I completely disagree.

I can't remember ever thinking that arrays and pointers were equivalent,
and I can see no reason why someone would need to believe that
particular fallacy before understanding why it is false. Explain one
concept in one lesson, make sure it is understood, explain the other
concept in another lesson and make sure it is understood, and then
explain that because of the way C implements arrays you don't pass
arrays and when you can treat one as the other.
--
Flash Gordon
Jun 3 '07 #8
"Malcolm McLean" <re*******@btinternet.comwrites:
[...]
Array - pointer equivalance is a classic case. Unless you go through a
stage of thinking that arrays and pointers are equivalent, you will
never understand why they are not equivalent.
Either I don't understand that statement, or I completely disagree
with it; I'm not sure which.

Surely it's possible for someone learning C to understand from the
beginning that arrays and pointers are very different things, if the
concepts are just explained correctly on the first exposure.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 3 '07 #9
Malcolm McLean wrote:
Array - pointer equivalance is a classic case. Unless you go through a
stage of thinking that arrays and pointers are equivalent, you will never
understand why they are not equivalent.
I don't think I ever went through the stage of believing that they
were equivalent, but I claim I understand why they are not.

Of course, C wasn't my first language -- it wasn't even my fourth --
and I hacked BCPL before I ever met C in real life.

--
"Anything can happen in the next half-hour." /Stingray/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Jun 4 '07 #10

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
"Malcolm McLean" <re*******@btinternet.comwrites:
[...]
>Array - pointer equivalance is a classic case. Unless you go through a
stage of thinking that arrays and pointers are equivalent, you will
never understand why they are not equivalent.

Either I don't understand that statement, or I completely disagree
with it; I'm not sure which.

Surely it's possible for someone learning C to understand from the
beginning that arrays and pointers are very different things, if the
concepts are just explained correctly on the first exposure.
You've got an unusual mind. Which is probably a strength, as a programmer.
However most people think and learn in far less abstract way.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 7 '07 #11
"Malcolm McLean" <re*******@btinternet.comwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>"Malcolm McLean" <re*******@btinternet.comwrites:
[...]
>>Array - pointer equivalance is a classic case. Unless you go through a
stage of thinking that arrays and pointers are equivalent, you will
never understand why they are not equivalent.

Either I don't understand that statement, or I completely disagree
with it; I'm not sure which.

Surely it's possible for someone learning C to understand from the
beginning that arrays and pointers are very different things, if the
concepts are just explained correctly on the first exposure.
You've got an unusual mind. Which is probably a strength, as a
programmer. However most people think and learn in far less abstract
way.
I still disagree. I think most people are perfectly capable of
understanding C pointers and arrays without *ever* having the delusion
that they're the same thing. And anyone who's not capable of that
likely will never really understand either arrays or pointers.

(I'm not saying that anyone who has thought arrays and pointers are
the same thing can never understand them. The misconception is
unnecessary, not fatal.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 7 '07 #12
Keith Thompson wrote, On 07/06/07 08:02:
"Malcolm McLean" <re*******@btinternet.comwrites:
>"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>>"Malcolm McLean" <re*******@btinternet.comwrites:
[...]
Array - pointer equivalance is a classic case. Unless you go through a
stage of thinking that arrays and pointers are equivalent, you will
never understand why they are not equivalent.
Either I don't understand that statement, or I completely disagree
with it; I'm not sure which.

Surely it's possible for someone learning C to understand from the
beginning that arrays and pointers are very different things, if the
concepts are just explained correctly on the first exposure.
You've got an unusual mind. Which is probably a strength, as a
programmer. However most people think and learn in far less abstract
way.

I still disagree. I think most people are perfectly capable of
understanding C pointers and arrays without *ever* having the delusion
that they're the same thing. And anyone who's not capable of that
likely will never really understand either arrays or pointers.
I agree. I've managed to explain the concepts of arrays and pointer to
people who have NO programming experience. It is really very easy to
explain in a classroom.

Desks are arranged in a traditional way in the classroom. OK, here is a
2 dimensional array of desks. We will number the rows from 0, and the
columns from 0, so John is in desk[3][5].

Now for pointers. My finger is pointing to desk[3][5], now I'm going to
increment it, it is now pointing at desk[3][6] where Jenny is.

Simple. Then, once they understand the general concepts of arrays and
pointers you can go on to explain the wrinkles of array in C.

As I say, I know that this type of explanation works (possibly with a
bit more discussion) since I've used it with non-computer people and
managed to go on to explain why things are not working in buggy programs.
(I'm not saying that anyone who has thought arrays and pointers are
the same thing can never understand them. The misconception is
unnecessary, not fatal.)
Agreed.
--
Flash Gordon
Jun 7 '07 #13

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

Similar topics

12
by: Neil | last post by:
I previously posted re. this, but thought I'd try again with a summary of facts. I have an Access 2000 MDB with a SQL Server 7 back end. There is a view that is linked to the database via ODBC...
8
by: Nicolás Lichtmaier | last post by:
Hi, some time ago I've written an article about this issue. It explain some differences in Explorer's and Mozilla's JavaScript/DOM. It has recently changed its URL, This is the new one: ...
4
by: MacDermott | last post by:
I have an Access 2000 form with a subform in Datasheet view. When I click on an item in the header of the subform (the title at the top of one of the columns), I'd like to be able to capture the...
0
by: Mike | last post by:
I have a form that has a search button on it. The form has three text boxes, last name, first name, and bidder number. I put in a last name and click the search button. Clicking the search button...
2
by: Peter Gebauer | last post by:
Hello. This section works fine: CREATE TABLE torder ( id INT8 NOT NULL PRIMARY KEY ); CREATE TABLE torder_row ( id INT8 NOT NULL PRIMARY KEY,
2
by: tom c | last post by:
This is a question on the first walkthrough "Walkthrough: Creating a Basic Web Page in Visual Web Developer" http://msdn2.microsoft.com/en-us/library/k4cbh4dh.aspx It shows that when you first...
6
BradHodge
by: BradHodge | last post by:
Greetings all. I'm using Access 2003. I have a form that is not showing any of the controls in the Detail section when you switch to Form View. You can see and change the color of the Detail...
0
JamieHowarth0
by: JamieHowarth0 | last post by:
Hi folks, Bit of a newbie to ASP.NET but starting to get the swing of things - but have come upon a stumbling block. I'm developing an entire site in ASP.NET v3.5 AJAX. I've got a MultiView and...
2
by: John | last post by:
Hi there, I have a site that uses a Tree View navigation control, based on a web.sitemap file (via a SiteMapDataDource), which all works fine. My question is how do I set the top node to be...
5
Frinavale
by: Frinavale | last post by:
I'm playing with an ASP.NET MVC application and I've run into a bit of a problem. I am pretty new to ASP.NET MVC and just barely understand the basics to get things to work at this point. I have a...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.