Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Issue on assigning address to pointers |
| Date | 2015-11-17 18:45 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <n2fsfj$eth$1@dont-email.me> (permalink) |
| References | <dc62f43a-1725-496b-b36a-c3e196015b7d@googlegroups.com> <lnegfojzfu.fsf@kst-u.example.com> <d581d91c-402d-49ac-8c96-4587c79ab5d9@googlegroups.com> |
On 17/11/15 18:32, Alla _ wrote:
<snip>
> Here is a more extensive quote from Chapter 18th (it K&R 4th edition by Mark
> Burgess, 1999):
K = Brian W Kernighan (a world-famous computer scientist).
R = Dennis M Ritchie (a world-famous computer scientist, and the
designer of the C programming language).
Mark Burgess = Someone who not only doesn't know C as well as he thinks
he does, but also has adopted a name for his tutorial that he knows
perfectly well will mislead people into accepting it as authoritative.
>
> Note that, if there are not enough elements in the curly braces to account
> for every single element in an array, the remaining elements will be filled out
> with zeros.
See? He's not always wrong. (For "zeros", read "default static
initialisers, which are 0 for integers, 0.0 for doubles, a null pointer
value for pointers, etc".)
> Static variables are always guaranteed to be initialized to zero
> anyway,
Correct again.
> whereas auto or local variables are guaranteed to be garbage:
No such guarantee is provided. Rather, uninitialised objects have an
indeterminate value (i.e. you can't tell what it is) until such time as
a value is assigned to them. C does not define what will happen if your
program reads an indeterminate value.
> this is
> because static storage is created by the compiler in the body of a program,
> whereas auto or local storage is created at run time.
I would prefer to say that it's because the Standard guarantees the
default static initialisation behaviour, but not that of automatic objects.
> 18.10 Arrays and Pointers
> The information about how arrays are stored was not included just for in-
> terest. There is another way of looking at arrays which follows the BCPL
> idea of an array as simply a block of memory. An array can be accessed with
> pointers as well as with [] square brackets.
> The name of an array variable, standing alone, is actually a pointer to
> the first element in the array.
Not exactly. Rather, *in a value context*, it 'decays' into such a pointer.
Consider this code:
#include <stdio.h>
int main(void)
{
float *myptr = NULL;
float myarray[34] = {0};
printf("Mark Burgess is ");
if(sizeof myptr == sizeof myarray)
{
puts("RIGHT!");
}
else
{
puts("WRONG!");
}
return 0;
}
> For example: if an array is declared
> float numbers[34];
> then numbers is a pointer to the first floating point number in the array;
No, it's an array.
> numbers is a pointer in its own right.
No, it's an array.
> (In this case it is type 'pointer to
> float'.) So the first element of the array could be accessed by writing:
> numbers[0] = 22.3;
True enough. In this situation, numbers is being used in a value
context, and so for this expression it is treated *as if* it were a
pointer to the first element in the array. Nevertheless, numbers is
still an array, as demonstrated by the sizeof example above.
> or by writing
> *numbers = 22.3;
Again, this is because numbers is being used in a value context.
Your extended quote goes on to cite nonsense that I've already commented
on earlier, so I'll snip it.
--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 08:49 -0800
Re: Issue on assigning address to pointers James Kuyper <jameskuyper@verizon.net> - 2015-11-17 12:36 -0500
Re: Issue on assigning address to pointers Richard Heathfield <rjh@cpax.org.uk> - 2015-11-17 17:47 +0000
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:34 -0800
Re: Issue on assigning address to pointers Keith Thompson <kst-u@mib.org> - 2015-11-17 12:16 -0800
Re: Issue on assigning address to pointers James Kuyper <jameskuyper@verizon.net> - 2015-11-17 15:23 -0500
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:33 -0800
Re: Issue on assigning address to pointers Keith Thompson <kst-u@mib.org> - 2015-11-17 09:41 -0800
Re: Issue on assigning address to pointers Geoff <geoff@invalid.invalid> - 2015-11-17 10:03 -0800
Re: Issue on assigning address to pointers glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-17 20:31 +0000
Re: Issue on assigning address to pointers Geoff <geoff@invalid.invalid> - 2015-11-17 12:53 -0800
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:32 -0800
Re: Issue on assigning address to pointers Richard Heathfield <rjh@cpax.org.uk> - 2015-11-17 18:45 +0000
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:53 -0800
Re: Issue on assigning address to pointers Keith Thompson <kst-u@mib.org> - 2015-11-17 15:05 -0800
Re: Issue on assigning address to pointers Philip Lantz <prl@canterey.us> - 2015-11-19 21:16 -0800
Re: Issue on assigning address to pointers Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2015-11-17 15:47 -0800
Re: Issue on assigning address to pointers Barry Schwarz <schwarzb@dqel.com> - 2015-11-17 15:53 -0800
Re: Issue on assigning address to pointers Richard Heathfield <rjh@cpax.org.uk> - 2015-11-18 04:05 +0000
Re: Issue on assigning address to pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-17 19:41 +0000
Re: Issue on assigning address to pointers Stephen Sprunk <stephen@sprunk.org> - 2015-11-17 12:17 -0600
Re: Issue on assigning address to pointers Richard Heathfield <rjh@cpax.org.uk> - 2015-11-17 18:21 +0000
Re: Issue on assigning address to pointers Geoff <geoff@invalid.invalid> - 2015-11-17 10:36 -0800
Re: Issue on assigning address to pointers Richard Heathfield <rjh@cpax.org.uk> - 2015-11-17 18:46 +0000
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:49 -0800
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:47 -0800
Re: Issue on assigning address to pointers Richard Heathfield <rjh@cpax.org.uk> - 2015-11-17 18:51 +0000
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:55 -0800
Re: Issue on assigning address to pointers Geoff <geoff@invalid.invalid> - 2015-11-17 11:59 -0800
Re: Issue on assigning address to pointers Stephen Sprunk <stephen@sprunk.org> - 2015-11-17 12:58 -0600
Re: Issue on assigning address to pointers Richard Heathfield <rjh@cpax.org.uk> - 2015-11-17 19:12 +0000
Re: Issue on assigning address to pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-17 19:33 +0000
Re: Issue on assigning address to pointers Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-17 13:25 -0500
Re: Issue on assigning address to pointers Richard Heathfield <rjh@cpax.org.uk> - 2015-11-17 18:31 +0000
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:39 -0800
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-17 10:40 -0800
Re: Issue on assigning address to pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-17 19:40 +0000
Re: Issue on assigning address to pointers Geoff <geoff@invalid.invalid> - 2015-11-17 11:15 -0800
Re: Issue on assigning address to pointers James Kuyper <jameskuyper@verizon.net> - 2015-11-17 15:32 -0500
Re: Issue on assigning address to pointers Keith Thompson <kst-u@mib.org> - 2015-11-17 15:09 -0800
Re: Issue on assigning address to pointers supercat@casperkitty.com - 2015-11-17 15:41 -0800
Re: Issue on assigning address to pointers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-17 21:28 -0800
Re: Issue on assigning address to pointers supercat@casperkitty.com - 2015-11-17 23:18 -0800
Re: Issue on assigning address to pointers Geoff <geoff@invalid.invalid> - 2015-11-17 17:18 -0800
Re: Issue on assigning address to pointers James Kuyper <jameskuyper@verizon.net> - 2015-11-17 22:37 -0500
Re: Issue on assigning address to pointers Lőrinczy Zsigmond <zsiga@nospam.for.me> - 2015-11-18 11:27 +0100
Re: Issue on assigning address to pointers Keith Thompson <kst-u@mib.org> - 2015-11-18 06:13 -0800
Re: Issue on assigning address to pointers guinness.tony@gmail.com - 2015-11-24 02:46 -0800
Re: Issue on assigning address to pointers Keith Thompson <kst-u@mib.org> - 2015-11-24 09:21 -0800
Re: Issue on assigning address to pointers John Bode <jfbode1029@gmail.com> - 2015-11-24 05:01 -0800
Re: Issue on assigning address to pointers Keith Thompson <kst-u@mib.org> - 2015-11-24 09:22 -0800
Re: Issue on assigning address to pointers John Bode <jfbode1029@gmail.com> - 2015-11-24 06:47 -0800
Re: Issue on assigning address to pointers Alla _ <modelling.data@gmail.com> - 2015-11-25 06:44 -0800
csiph-web