Good Tutorials

A

Amkcoder

Amkcoder said:



You have been shown several counterexamples. Here are a few to refresh your
memory:

malloc(256)
myarray + offset
&integerobject
printf

None of these pointers is a variable that holds the address of another
variable. So now you have three choices:

1) accept that you're wrong;
2) explain why the counterexamples don't apply;
3) neither of the above.

1) and 2) are both honourable options, but 3) just suggests that you don't
know what you're talking about.


Not true. For example, here's a declaration of a pointer that doesn't
allocate any bytes at all:

extern int *p;



Why? You have not yet convinced me that you have the slightest idea what
you're talking about.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

A byte, typicaly, as the most common systems I have used is 8-bits in
length.
As is confirmed at wikipedia http://en.wikipedia.org/wiki/Byte
On x86 architecture based systems and compatibles,
it is confirmed that a word is two contiguous bytes,
each of which have their own address,
and the lower of the addresses is the address of the word.
This makes a 16-bit value.
As can be seen in this archecture it requires a double word (32-bit
binary value)
to represent every address,
for it can address up to 2^32-1 bytes,
and as can be seen a double word contains 32-bits having
a maximum value of 2^32-1 when unsigned
, for on these systems each address refers to a byte.
To program on the x86 architecture it is requisite knowledge.
This is the most common of architectures, so to be a real programmer,
capable working in the real world on most systems,
you'll need this manual for the 80386, or the newer ones:
http://www.cs.ucla.edu/~kohler/class/aos-f04/ref/i386.pdf
PS, the applications programming section, chapter on datatypes
confirms all that I have said in the above pdf.
This proves I am a programmer, capable of programmer x86 based
processors.
So if you have a x86 based processor, which you most likely do,
compile and run the following:
It will print out the value 666, and the size (in bytes) of a short
int,
on your x86 system. Enjoy:

#include <stdio.h>

int main() {
short int a;
unsigned char *b=(unsigned char *)&a;
*b=154;
*(b+1)=2;
printf("%d \n",a);
printf("%d bytes for short int \n",sizeof(short int));
system("pause");
}
 
A

Amkcoder

Amkcoder said:



You have been shown several counterexamples. Here are a few to refresh your
memory:

malloc(256)
myarray + offset
&integerobject
printf

None of these pointers is a variable that holds the address of another
variable. So now you have three choices:

1) accept that you're wrong;
2) explain why the counterexamples don't apply;
3) neither of the above.

1) and 2) are both honourable options, but 3) just suggests that you don't
know what you're talking about.


Not true. For example, here's a declaration of a pointer that doesn't
allocate any bytes at all:

extern int *p;



Why? You have not yet convinced me that you have the slightest idea what
you're talking about.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

A byte, typicaly, as the most common systems I have used is 8-bits in
length.
As is confirmed at wikipedia http://en.wikipedia.org/wiki/Byte
On x86 architecture based systems and compatibles,
it is confirmed that a word is two contiguous bytes,
each of which have their own address,
and the lower of the addresses is the address of the word.
This makes a 16-bit value.
As can be seen in this archecture it requires a double word (32-bit
binary value)
to represent every address,
for it can address up to 2^32-1 bytes,
and as can be seen a double word contains 32-bits having
a maximum value of 2^32-1 when unsigned
, for on these systems each address refers to a byte.
To program on the x86 architecture it is requisite knowledge.
This is the most common of architectures, so to be a real programmer,
capable working in the real world on most systems,
you'll need this manual for the 80386, or the newer ones:
http://www.cs.ucla.edu/~kohler/class/aos-f04/ref/i386.pdf
PS, the applications programming section, chapter on datatypes
confirms all that I have said in the above pdf.
This proves I am a programmer, capable of programmer x86 based
processors.
So if you have a x86 based processor, which you most likely do,
compile and run the following:
It will print out the value 666, and the size (in bytes) of a short
int,
on your x86 system. Enjoy:

#include <stdio.h>

int main() {
short int a;
unsigned char *b=(unsigned char *)&a;
*b=154;
*(b+1)=2;
printf("%d \n",a);
printf("%d bytes for short int \n",sizeof(short int));
system("pause");
}
 
A

Amkcoder

Amkcoder said:



You have been shown several counterexamples. Here are a few to refresh your
memory:

malloc(256)
myarray + offset
&integerobject
printf

None of these pointers is a variable that holds the address of another
variable. So now you have three choices:

1) accept that you're wrong;
2) explain why the counterexamples don't apply;
3) neither of the above.

1) and 2) are both honourable options, but 3) just suggests that you don't
know what you're talking about.


Not true. For example, here's a declaration of a pointer that doesn't
allocate any bytes at all:

extern int *p;



Why? You have not yet convinced me that you have the slightest idea what
you're talking about.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

A byte, typicaly, as the most common systems I have used is 8-bits in
length.
As is confirmed at wikipedia http://en.wikipedia.org/wiki/Byte
On x86 architecture based systems and compatibles,
it is confirmed that a word is two contiguous bytes,
each of which have their own address,
and the lower of the addresses is the address of the word.
This makes a 16-bit value.
As can be seen in this archecture it requires a double word (32-bit
binary value)
to represent every address,
for it can address up to 2^32-1 bytes,
and as can be seen a double word contains 32-bits having
a maximum value of 2^32-1 when unsigned
, for on these systems each address refers to a byte.
To program on the x86 architecture it is requisite knowledge.
This is the most common of architectures, so to be a real programmer,
capable working in the real world on most systems,
you'll need this manual for the 80386, or the newer ones:
http://www.cs.ucla.edu/~kohler/class/aos-f04/ref/i386.pdf
PS, the applications programming section, chapter on datatypes
confirms all that I have said in the above pdf.
This proves I am a programmer, capable of programmer x86 based
processors.
So if you have a x86 based processor, which you most likely do,
compile and run the following:
It will print out the value 666, and the size (in bytes) of a short
int,
on your x86 system. Enjoy:

#include <stdio.h>

int main() {
short int a;
unsigned char *b=(unsigned char *)&a;
*b=154;
*(b+1)=2;
printf("%d \n",a);
printf("%d bytes for short int \n",sizeof(short int));
system("pause");
}
 
K

Keith Thompson

Amkcoder said:
This proves I am a programmer, capable of programmer x86 based
processors.
So if you have a x86 based processor, which you most likely do,
compile and run the following:
It will print out the value 666, and the size (in bytes) of a short
int,
on your x86 system. Enjoy:

#include <stdio.h>

int main() {
short int a;
unsigned char *b=(unsigned char *)&a;
*b=154;
*(b+1)=2;
printf("%d \n",a);
printf("%d bytes for short int \n",sizeof(short int));
system("pause");
}

Most of your articles are appearing several times. This isn't an
uncommon problem with Google Groups, but most users don't have as much
trouble with it as you do.

Please don't quote the entire article to which you're replying. In
particular, don't quote signatures (the part following the "-- "
delimiter) unless you're actually commenting on them.

We don't just discuss x86 processors here; we discuss the C
programming language, which is implemented on processors you've
probably never heard of.

But ok, I'll try your program on my x86 system:

% gcc -ansi -pedantic -Wall -Wextra c.c -o c
c.c: In function 'main':
c.c:10: warning: implicit declaration of function 'system'
c.c:11: warning: control reaches end of non-void function
% ./c
666
2 bytes for short int
sh: pause: not found

And here's the same program on a SPARC system:

% cc -Xc c.c -o c
"c.c", line 10: warning: implicit function declaration: system
% ./c
-26110
2 bytes for short int
sh: pause: not found

And there are other systems where your statement

printf("%d bytes for short int \n",sizeof(short int));

is likely to produce garbage, because you're using "%d" for an
argument of type size_t (I've used systems where int is 32 bits and
size_t is 64 bits). I don't have easy access to any such systems at
the moment.

You can learn a lot here if you'll just drop the arrogant attitude and
realize that many of us actually know things that you don't,
notwithstanding your years of experience as a Professional Programmer.
The world of C is a lot bigger than you seem to think it is.

And who knows, maybe you could teach us a few things too, though so
far everything you've told us is stuff that (a) we already know, and
(b) we know isn't even close to being the whole story.
 
J

jameskuyper

Amkcoder said:
Amkcoder said:


On Sep 23, 9:03 am, (e-mail address removed) wrote:
Amkcoder wrote:

The definition you so waywardly complain about is repeated as a common
definition:
"A pointer is a variable that points at, or refers to, another
variable."
So, if we have
char greeting[] = "Hello, World!";
int seven = 7;
Then according to your definition, neither greeting+6 nor &seven are
pointers, because they are expressions, not variables. According to
your definition, neither (void*)0 nor malloc(256) is a pointer, both
because they aren't variables and because they don't point at
variables.
I consider this to be a serious defect in your definition of a
pointer.

Like I said, good tutorials...
Please only sincere students or real programmers comment,
I'm a real programmer. At least, they pay me to write computer
programs. And I know, as you apparently do not, that pointers don't
need to be variables, and they don't need to point at variables.
Sorry,
but a short int is exactly two bytes,

No, a short int is at least 16 bits, and at least one byte, in width, but
there is no upper limit.
and in order to use them they
must be treated as a
word.

No, they must be treated as short ints (modulo object representation
techniques which don't seem to be relevant here).
You think I don't know that you can refer a pointer to allocated
memory,
it is in my tutorial.

He's not saying you don't know that. He's saying your definition of a
pointer fails to take it into account.
When you declare a short int the compiler allocates two bytes for it

No, when you *define* a short int, the implementation allocates
sizeof(short int) bytes for it. This may be 2, but may only be 1 (on
systems with chars at least 16 bits wide), or could be 3 or 4 or 42 or
whatever. 2 is common, it's true. I've seen 1, and I've heard of 8.
To prove you wrong I will show you the following:
short int *sint=malloc(2);
unsigned char *a=(unsigned char *)sint;
*a=154;
*(a+1)=2;
printf("%d",*sint);
Check out the value it prints out...

You appear to think that the behaviour you observe on your system
represents fundamental truths about C. It doesn't.
They must pay you minimum wage just to crank out code.
I am a real programmer, 14 years in the making.

How nice. But you would do well to listen to James. He's what they call an
"expert".

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

The reason Universities, who make real programmers,

Universities make entry level programmers. It's experience that makes
professional programmers. I remember when I was looking for my first
job: I knew how to use every single feature of the C language, and
most of the functions in the C standard library. I thought I knew
everything I needed to program in C, and wondered why so few people
were willing to hire me. It wasn't until several years later I
realized just how much I hadn't known yet at that time. I've had to
hire entry level programmers, because we couldn't afford the more
experienced ones, and it can take from three months to a year to train
one up to the point where I spend less time showing him how to do
something, than it would have taken me to do it myself.
say that a pointer
is a variable
that holds the address of another, it is.
This is because every time you declare a pointer it allocates enough
bytes to hold
a value, which will be treated as an address,

OK, then please tell me where "it" allocates the bytes to hold the
pointer value of "&seven"? On most of the machines I've used, it would
likely remain in a register,
... and this space has its
own address just like a
variable.

Pointers often reside in registers, which don't have addresses (at
least, on most of the machines I've used - I've heard that there are
other machines where registers do have addresses). However, even for
pointers which are stored in actual objects, that doesn't prove that
they are stored in variables. A variable is a named object, and
objects often have no name, for instance objects stored in memory
allocated with malloc().
 
F

Flash Gordon

Amkcoder wrote, On 23/09/08 17:50:

The reason universities, who make real programmers, use the definition
that a pointer
is a variable that holds the address to another variable in memory, is
because
it is.

I'll admit that the word "pointer" is often used to refer to a variable
of type pointer to something. It's a good way to confuse people though
because that is not the only way the word is commonly used.
Every time you declare a pointer space is allocated for it to hold a
value,
which will be treated as an address. This space has its own address,
just like a variable.

Since you are using the word "pointer" to mean a "pointer variable" then
it not only has its own address just like a variable it *is* a variable.
This leads to another mistake in your tutorial. You say...
The address of memory allocated by a declared variable may be retrieved
with the address of operator for assignment to a pointer, or for
later storage.
This works on any variable but pointers, if it is a pointer one
may retrieve the address it holds by excluding the asterik prefixed
to its identifier.

This is wrong. The address operator "&" works perfectly well on pointer
variables, I know because the standard says so and I use it. Of course,
it doesn't give you the value the pointer variable contains, but in that
respect it is _exactly_the_same_ as every other variable.
So that every time a pointer is declared the same amount of space is
allocated
capable of holding an address. The pointer's type merely indicates how
to treat the data it refers to when it is dereferenced.
So he is an expert,
then call me the professional.

You would not even get through the interview anywhere that I have worked.

Another error is that you seem to think that adding one to a pointer
increments it by one byte and that if you want to increment through some
type larger than a byte you have to add sizeof(type) to a pointer. This
is complete and utter rubbish. You then go on to ignore allignment
issues giving this final piece of badly broken code...
unsigned char *char_ptr=malloc(sizeof(char)+sizeof(short int));
short int *int_ptr=(short int *)char_ptr+1;
*char_ptr=123;
*int_ptr=510;
printf("%d %d",*char_ptr,*int_ptr);

Just for amusement I've expanded it to a complete program...
markg@brenda:~$ cat t.c
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
unsigned char *char_ptr=malloc(sizeof(char)+sizeof(short int));
short int *int_ptr=(short int *)char_ptr+1;
*char_ptr=123;
*int_ptr=510;
printf("%d %d",*char_ptr,*int_ptr);
printf("\n%p %p\n",(void*)char_ptr,(void*)int_ptr);
return 0;
}
markg@brenda:~$ gcc -ansi -pedantic -Wall -Wextra -g3 t.c
markg@brenda:~$ ./a.out
123 510
0x804a008 0x804a00a
markg@brenda:~$
Note that the addresses are two apart not 1 as you thought. This also
means that as on this machine short is two bytes it reads/writes beyond
the end of the allocated memory. For your information I also ran it
through a memory checker which reports this problem...
markg@brenda:~$ valgrind --tool=memcheck ./a.out
==5552== Memcheck, a memory error detector.
==5552== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==5552== Using LibVEX rev 1804, a library for dynamic binary translation.
==5552== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==5552== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation
framework.
==5552== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==5552== For more details, rerun with: -v
==5552==
==5552== Invalid write of size 2
==5552== at 0x80483D6: main (t.c:9)
==5552== Address 0x418d02a is 2 bytes inside a block of size 3 alloc'd
==5552== at 0x4022AB8: malloc (vg_replace_malloc.c:207)
==5552== by 0x80483C0: main (t.c:6)
==5552==
==5552== Invalid read of size 2
==5552== at 0x80483DE: main (t.c:10)
==5552== Address 0x418d02a is 2 bytes inside a block of size 3 alloc'd
==5552== at 0x4022AB8: malloc (vg_replace_malloc.c:207)
==5552== by 0x80483C0: main (t.c:6)
123 510
0x418d028 0x418d02a
==5552==
==5552== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 11 from 1)
==5552== malloc/free: in use at exit: 3 bytes in 1 blocks.
==5552== malloc/free: 1 allocs, 0 frees, 3 bytes allocated.
==5552== For counts of detected errors, rerun with: -v
==5552== searching for pointers to 1 not-freed blocks.
==5552== checked 60,204 bytes.
==5552==
==5552== LEAK SUMMARY:
==5552== definitely lost: 3 bytes in 1 blocks.
==5552== possibly lost: 0 bytes in 0 blocks.
==5552== still reachable: 0 bytes in 0 blocks.
==5552== suppressed: 0 bytes in 0 blocks.
==5552== Rerun with --leak-check=full to see details of leaked memory.
markg@brenda:~$

One final point, you are not fluent enough in English to write a good
tutorial in English. You lack of fluency probably makes your tutorial
worse than it would be if you wrote it in your first language.
 
J

jameskuyper

Richard said:
What absolute nonsense. The behaviour on a conforming system must be a
truth or it would not be conforming.

Just because it's true doesn't make it fundamental.

On systems where that code has defined behavior, it is likely to print
either 154*UCHAR_MAX+156, 2*UCHAR_MAX+156, or 154, though other values
are permitted (the order of the bits within an unsigned char are not
required to have any particular relationship with the order of the
bits within an int). On systems where it has undefined behavior, it
could print out anything (or nothing), or engage in some kind of
behavior that has nothing to do with printing. With such a wide
variety of permitted behavior, how could the result produced by any
given implementation of C reveal any truth about C that you would
consider fundamental? What truth would that be?
 
J

jameskuyper

Amkcoder said:
A byte, typicaly, as the most common systems I have used is 8-bits in
length.

Just keep in mind that not all systems have 8-bit bytes.
As is confirmed at wikipedia http://en.wikipedia.org/wiki/Byte
On x86 architecture based systems and compatibles,
it is confirmed that a word is two contiguous bytes,

Just keep in mind that not all C implementations run on x86
architectures.
each of which have their own address,
and the lower of the addresses is the address of the word.
This makes a 16-bit value.
As can be seen in this archecture it requires a double word (32-bit
binary value)
to represent every address,
for it can address up to 2^32-1 bytes,
and as can be seen a double word contains 32-bits having
a maximum value of 2^32-1 when unsigned
, for on these systems each address refers to a byte.
To program on the x86 architecture it is requisite knowledge.

Not at all. It's quite feasible to write useful programs for x86
architectures which make no use whatsoever of any implementation-
specific feature you've described above. Most of my code, for
instance, makes no use of any of that information, despite the fact
that it runs mostly on Linux x86 machines (it also runs on SGI Irix
machines. It should also work on Windows and Mac machines, but I don't
have access to any machine where I can test that assumption, so I
can't be sure).
This is the most common of architectures, so to be a real programmer,

Don't count on it. For every x86 machine, there's multiple embedded
processors on the very same board with it, in addition to all of the
embedded processors in all of the other devices in the world. I'm not
sure that there's any one embedded processor that is more common than
the entire x86 family of processors, but collectively I'm quite sure
that embedded processors vastly outnumber x86 processors, and most of
those embedded processors have environments significantly different
from the one you describe.

I can't prove from my personal knowledge that more C programming is
being performed for embedded processors than for all other platforms
combined; but I have heard that claim made, and I don't know of any
reason to doubt it. It's certainly a major development area,
regardless of what the actual quantities of code are.
capable working in the real world on most systems,

Even if x86 machines are the most common, that doesn't mean that
they're more common than all other types combined. Your use of the
phrase "most systems" had better be justified with some hard numbers.
you'll need this manual for the 80386, or the newer ones:
http://www.cs.ucla.edu/~kohler/class/aos-f04/ref/i386.pdf

No, you don't. It's useful information, for some kinds of x86
programming, and completely irrelevant for other kinds of x86
programming, and it's completely irrelevant for all kinds of
programming on any system that doesn't happen to be an x86 machine.
PS, the applications programming section, chapter on datatypes
confirms all that I have said in the above pdf.
This proves I am a programmer, capable of programmer x86 based
processors.

Not really. It only proves that you think "everything's an x86". A
real programmer knows what he can and cannot rely on when porting to
different platforms, and you make it sound like you have a serious
shortage of knowledge on that subject.
 
B

Bartc

Keith said:
But it could well stop you from communicating effectively about them.

And I think you overestimate your own ignorance. For example, given:

int x;
int *obj = &x;

I think you know that obj is an object (and a variable), &x is a
value, and int* is a type.

Sure, when you stop to think about these things. But sometimes thinking too
much about something obvious is counter-productive: is x an integer, or the
address of an integer, or just a symbol? Suddenly things get complicated.

"A pointer is a variable that holds the address of another variable..." or
whatever it was, is a little sloppy but a reasonable starting point. Maybe
the pointer may not be in a variable, sometimes it doesn't point to another
variable...etc. That can wait for a subsequent tutorial.
 
S

soscpd

Hi List

But a pointer may also be a pointer to function which does not point
to an object at all.

Mmm... did the function (pointer) return something? That is not the
"why" we can use function pointers?

Did anyone know a pointer to something who will not return any value?

Can anyone find a better definition then "pointer" itself?
I mean.... pointer is ... a pointer?


Regards
Rafael
 
C

CBFalconer

Ben said:
Richard Heathfield said:
MisterE said:


People who take the time to learn their subject properly are
more likely to get more stuff done more quickly than people who
just grab a screwdriver and start poking around at random.

Ignoring, if I may, the appalling wordsmithery, I count three
errors of fact in that first paragraph.

I count only 2 and half. Why not tell us your three[1]?

Interesting fact from my teaching: I'd explain some concept to
student A carefully using all the right terms. Because both the
concept and terms are new, students A looks a little baffled.
Before I can have another go, student B -- listen in -- repeats
what I have said in different (more common) words thereby
introducing several technical errors. Student A goes "Ah, I get
it" and repeats it using yet more terms with yet more errors of
fact. I used not to walk away in my early years but I soon
learnt it was better to walk away saying "that's the gist of it"
and making a note to correct some of the technical details later.

This reminds me of an experience I had about 10 or 15 years ago. I
decided to take a crack at teaching in a technical college, and got
hired for a trial. First I was put in to monitor actual teaching
in a class on elementary electricity and components. I listened to
the teacher, and was horrified at the inaccuracies he was
teaching. I resolved I could do better.

So I got to try out my technique. I accurately explained various
things. Then I looked at the class, and was greeted with
dumbfounded looks. From both the bright and the dumb. So I tried
the explanation again, varying something in the verbiage. No luck.

In part, I was explaining things I had lived with for umpty-ump
years. So they are obvious, and how could anybody misapprehend
them?

At any rate, after roughly a month of this sort of thing, the
powers that were decided that I was not quite cut out to teach in a
technical school. By that time I agreed, and we parted company.

From then on I have been left with admiration for the way the
demonstrating teacher managed to explain things with inaccurate
explanations. It is still beyond me, but I don't worry as much
about absolute accuracy any more. You can treat lines of magnetic
flux as lines, rather than fields. Depending on the destination,
you may want to include that this is simply one way of looking at
it.
 
C

CBFalconer

Amkcoder said:
.... snip ...

Sorry, but a short int is exactly two bytes, and in order to use
them they must be treated as a word. You think I don't know that
you can refer a pointer to allocated memory, it is in my tutorial.

Not so. However, you can always find out how many bytes a short
uses by examining <limits.h> for that system.
 
J

jameskuyper

soscpd said:
Hi List



Mmm... did the function (pointer) return something? That is not the
"why" we can use function pointers?

I'm not quite sure what you mean by those questions. A function
pointer does not "return" anything. It points at the entry point for a
function, which does not qualify as an "object" as far as the C
standard is concerned. It can be used to call the function that it
points at. That is the reason why we use function pointers. The
function call may return something, but the function pointer itself
does not.
Did anyone know a pointer to something who will not return any value?

It has a value, which is the location of the function it points at. It
doesn't "return" that value.
Can anyone find a better definition then "pointer" itself?
I mean.... pointer is ... a pointer?

The standard doesn't define "pointer" but it does define a "pointer
type":

6.2.5p20: "A pointer type describes an object whose value provides a
reference to an entity of the referenced type."

Notice how the use of the term "entity" neatly side-steps the object
pointer/function pointer distinction.

It is commonplace to use the term pointer to mean either a "pointer
object" or a "pointer value", both usages are common in the standard
itself. This occasionally leads to confusion. Amkcorder's definition
comes closer to being correct if it defines a pointer object; it
doesn't work at all as a definition of a pointer value.
Fundamentally, I think his problem is that he confuses "object" with
"variable". The standard doesn't define what the word "variable"
means, but the most reasonable definition I'm familiar with is that,
in C terms, a variable is a named object. With that definition for
"variable", his definition of "pointer" is incorrect, whether it's
meant to define a pointer object or a pointer value.
 
K

Keith Thompson

CBFalconer said:
Not so. However, you can always find out how many bytes a short
uses by examining <limits.h> for that system.

ITYM sizeof(short). The information in <limits.h> is likely to tell
you how many bytes a short occupies, but it doesn't account for
padding bits.
 
C

CBFalconer

Amkcoder said:
(e-mail address removed) wrote:
.... snip ...


Sorry, when you declare a short int it allocates two bytes and
associates the beginning of the address to the two bytes to your
variable.

You have already been told many times that a short is not
necessarily a two byte object. Why do you repeat this
misinformation?
 
A

Anand Hariharan

I'm not
sure that there's any one embedded processor that is more common than
the entire x86 family of processors,

The empirical evidence is fairly overwhelming to suggest that there
isn't one (especially since you pit it against the entire x86 family).

but collectively I'm quite sure
that embedded processors vastly outnumber x86 processors, and most of
those embedded processors have environments significantly different
from the one you describe.

I can easily agree with that. It's just that they are so diverse and
fragmented, one can easily conclude that x86 is what is out there.


- Anand
 
M

Mark L Pappin

CBFalconer said:
I listened to the teacher, and was horrified at the inaccuracies he
was teaching. I resolved I could do better.

So I got to try out my technique. I accurately explained various
things. Then I looked at the class, and was greeted with
dumbfounded looks. ....
From then on I have been left with admiration for the way the
demonstrating teacher managed to explain things with inaccurate
explanations.

Terry Pratchett, Ian Stewart, and Jack Cohen (in their several
"Science of Discworld" books) describe the technique as "Telling Lies
To Children", where the Lies become incrementally more accurate as the
Children's understanding becomes more complete.

Some Children need particularly blatant Lies and take a while to get
used to revisions, and some refuse to accept later revisions at all.
We see examples of both here.

In an ideal world with perfectly rational students perhaps one could
begin by stating "What I am about to tell you is not completely
correct, but is a necessary simplification to bootstrap this model of
reality into your brain. Later, as your understanding grows, you will
need to throw out some of these simplifications to allow you to see
better models." We don't have such a world, unfortunately.

mlp
 
B

Ben Bacarisse

Amkcoder said:
Richard Heathfield said:
MisterE said:
"A pointer in C is a variable which holds the address of another
variable in memory. They are useful for dynamicly allocated memory which
may be deallocated when nolonger needed,linked lists,writing to memory
external to the program,and allowing invoked functions to manipulate the
data of variables outside their scope. These have many uses and are
necessary to successfull programming in C."
Oh deary deary me.
Yeah sounds like its written for people who actually want to get stuff
done, instead of written for people who want to be anal over definitions.
People who take the time to learn their subject properly are more likely to
get more stuff done more quickly than people who just grab a screwdriver
and start poking around at random.
Ignoring, if I may, the appalling wordsmithery, I count three errors of
fact in that first paragraph.

I count only 2 and half. Why not tell us your three[1]?

Interesting fact from my teaching: I'd explain some concept to student
A carefully using all the right terms. Because both the concept and
terms are new, students A looks a little baffled. Before I can have
another go, student B -- listen in -- repeats what I have said in
different (more common) words thereby introducing several technical
errors. Student A goes "Ah, I get it" and repeats it using yet more
terms with yet more errors of fact. I used not to walk away in my
early years but I soon learnt it was better to walk away saying
"that's the gist of it" and making a note to correct some of the
technical details later.

Now, a tutorial is different, but it may later correct this sloppy
start.

[1] Mine are: a pointer is a value not a variable. They address
objects not variables (that, to me, is the half) and I don't like the
idea of "memory external to the program". If you have a pointer you
can write though, it is your data (even if the OS wishes it were
not!).

Best not quote sig blocks.
The definition you so waywardly complain about is repeated as a common
definition:

Did you not see that I was suggesting that the criticism was maybe a
little harsh, given that fact that it is often OK in my opinion to
gloss over details and use vague terms (like variable) in order to get
the idea across.
"A pointer is a variable that points at, or refers to, another
variable."
http://www.eskimo.com/~scs/cclass/notes/sx10.html, even at
universities.

We all make mistakes. I think that page is very good, but it would be
better if "variable" was replaced by "value" in the sentence.
Using memory external to a program, is sometimes also necessary, like
writing directly to video memory, or using the DOS inter application
communication
are, are is said here:
http://www.osdata.com/system/physical/lowmem.htm#usercommo

It is simply a matter of definition. To you, a program can write
(using a pointer) to memory that is not "in" the program. I would
prefer to define a program's memory as those locations it can write
to. Neither one helps to explain C pointers since they are neither
necessary nor sufficient for the task. Personally, I'd leave such a
notion out altogether when teaching beginners about pointers
ARE YOU GUYS EVEN PROGRAMMERS?
You could not point out why when you said I was wrong.

Like I said, good tutorials...
Please only sincere students or real programmers comment,
others just waste space...

Oh sorry. I should have read that first. I am neither so please
ignore the above.
 
B

Ben Bacarisse

Richard said:
This constant desire to confuse people with a "pointer is not an
address" is simply ridiculous. It is an "address".

You are putting words into people's mouths again. Who has said this
here? I will gladly go and post a comment. & is called (in the C
standard) the address operator. It produces a value of type "pointer
to...". The terms are close to be synonymous in C.

People have, correctly, objected to your simplification that and
pointer and/or an address is a number, because that will suggest to
some people that more can be done with it than is, is fact,
permitted.

[I snipped everything because I could not find anything to support
Richard's claim in the message he replied to.]
 
B

Ben Bacarisse

Tony Mc said:
[1] Mine are: a pointer is a value not a variable. They address
objects not variables

But a pointer may also be a pointer to function which does not point
to an object at all.

Good point. I should, maybe, just have stuck to the point I wanted to
make: that they don't always address variables as was stated.
 

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
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top