Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #12875 > unrolled thread
| Started by | arnuld <sunrise@invalid.address> |
|---|---|
| First post | 2011-11-08 07:51 +0000 |
| Last post | 2011-11-08 06:19 -0500 |
| Articles | 20 on this page of 40 — 16 participants |
Back to article view | Back to comp.lang.c
Array of Integers ? arnuld <sunrise@invalid.address> - 2011-11-08 07:51 +0000
Re: Array of Integers ? Ike Naar <ike@iceland.freeshell.org> - 2011-11-08 08:11 +0000
Re: Array of Integers ? jacob navia <jacob@spamsink.net> - 2011-11-08 09:14 +0100
Re: Array of Integers ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-11-08 00:23 -0800
Re: Array of Integers ? pete <pfiland@mindspring.com> - 2011-11-08 04:07 -0500
Re: Array of Integers ? tom st denis <tom@iahu.ca> - 2011-11-08 06:23 -0800
Re: Array of Integers ? "Scott Fluhrer" <sfluhrer@ix.netcom.com> - 2011-11-08 10:08 -0500
Re: Array of Integers ? Noob <root@127.0.0.1> - 2011-11-08 16:25 +0100
Re: Array of Integers ? bks@panix.com (Bradley K. Sherman) - 2011-11-08 15:39 +0000
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-08 13:48 -0800
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-09 19:34 -0800
Re: Array of Integers ? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-11-08 06:59 -0800
Re: Array of Integers ? jacob navia <jacob@spamsink.net> - 2011-11-08 22:48 +0100
Re: Array of Integers ? Chad <cdalten@gmail.com> - 2011-11-08 07:12 -0800
Re: Array of Integers ? pete <pfiland@mindspring.com> - 2011-11-08 11:49 -0500
Re: Array of Integers ? James Kuyper <jameskuyper@verizon.net> - 2011-11-08 12:13 -0500
Re: Array of Integers ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-11-08 21:45 +0000
Re: Array of Integers ? James Kuyper <jameskuyper@verizon.net> - 2011-11-08 16:48 -0500
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-08 14:25 -0800
Re: Array of Integers ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-11-08 22:42 +0000
Re: Array of Integers ? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-11-10 12:01 +0200
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-10 03:14 -0800
Re: Array of Integers ? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-11-10 17:41 +0200
Re: Array of Integers ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-11-10 16:44 +0000
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-10 10:59 -0800
Re: Array of Integers ? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-11-11 17:49 +0200
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-08 14:00 -0800
Re: Array of Integers ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-11-09 00:57 +0000
Re: Array of Integers ? pete <pfiland@mindspring.com> - 2011-11-09 00:05 -0500
Re: Array of Integers ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-11-09 11:06 +0000
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-09 13:36 -0800
Re: Array of Integers ? Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 00:45 -0800
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2012-01-25 02:56 -0800
Re: Array of Integers ? pete <pfiland@mindspring.com> - 2011-11-09 18:34 -0500
Re: Array of Integers ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-11-10 00:57 +0000
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-08 22:14 -0800
Re: Array of Integers ? Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 01:46 -0800
Re: Array of Integers ? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-11-08 01:39 -0800
Re: Array of Integers ? Keith Thompson <kst-u@mib.org> - 2011-11-08 14:05 -0800
Re: Array of Integers ? James Kuyper <jameskuyper@verizon.net> - 2011-11-08 06:19 -0500
Page 1 of 2 [1] 2 Next page →
| From | arnuld <sunrise@invalid.address> |
|---|---|
| Date | 2011-11-08 07:51 +0000 |
| Subject | Array of Integers ? |
| Message-ID | <4eb8df96$0$281$14726298@news.sunsite.dk> |
I wrote my blog on Insertion Sort some time back and used words "Array of Integers" on that. I was told by someone that there is nothing like array of integers in C. C has array of objects only. So how do we differentiate between array of integers and array of characters (not string constant) in communication if there is no such thing as array of integers ? -- arnuld http://LispMachine.Wordpress.com
[toc] | [next] | [standalone]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Date | 2011-11-08 08:11 +0000 |
| Message-ID | <slrn3vfsjbhp10.3cv.ike@iceland.freeshell.org> |
| In reply to | #12875 |
On 2011-11-08, arnuld <sunrise@invalid.address> wrote: > I wrote my blog on Insertion Sort some time back and used words "Array of > Integers" on that. I was told by someone that there is nothing like array > of integers in C. C has array of objects only. > > So how do we differentiate between array of integers and array of > characters (not string constant) in communication if there is no such > thing as array of integers ? By their names.
[toc] | [prev] | [next] | [standalone]
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2011-11-08 09:14 +0100 |
| Message-ID | <j9aocd$9b5$1@speranza.aioe.org> |
| In reply to | #12875 |
Le 08/11/11 08:51, arnuld a écrit :
> I wrote my blog on Insertion Sort some time back and used words "Array of
> Integers" on that. I was told by someone that there is nothing like array
> of integers in C. C has array of objects only.
>
> So how do we differentiate between array of integers and array of
> characters (not string constant) in communication if there is no such
> thing as array of integers ?
>
>
>
You define an array of integers like this:
int array[256];
The person that told you that arrays of integers do not exist in C is
completely wrong.
In general you declara an array like this:
TYPE ArrayName [ array-size ] ;
For instance:
double array[256];
or
char array[256];
In general since a standard string is an array of characters finished
by a zero character there is no way of distinguishing it from an array
of characters that is zero terminated.
char array[] = { 'a', 'b', 0};
This has the same representation as the string "ab".
[toc] | [prev] | [next] | [standalone]
| From | Nick Keighley <nick_keighley_nospam@hotmail.com> |
|---|---|
| Date | 2011-11-08 00:23 -0800 |
| Message-ID | <b1869e7d-eaed-4bbc-a1cf-1bbea74ee88c@3g2000vbp.googlegroups.com> |
| In reply to | #12877 |
On Nov 8, 8:14 am, jacob navia <ja...@spamsink.net> wrote:
> Le 08/11/11 08:51, arnuld a écrit :
> > I wrote my blog on Insertion Sort some time back and used words "Array of
> > Integers" on that. I was told by someone that there is nothing like array
> > of integers in C. C has array of objects only.
>
> > So how do we differentiate between array of integers and array of
> > characters (not string constant) in communication if there is no such
> > thing as array of integers ?
>
> You define an array of integers like this:
>
> int array[256];
>
> The person that told you that arrays of integers do not exist in C is
> completely wrong.
I agree. The array-of-T terminology has been around for an age. cdecl
and such like use the terminology.
Ah, from the standrard (draft '89)
* An array type describes a contiguously allocated set of objects
with a particular member object type, called the element
type .Array
types are characterized by their element type and by the number of
members of the array. An array type is said to be derived from its
element type, and if its element type is T , the array type is
sometimes called ``array of T .'' The construction of an array type
from an element type is called ``array type derivation.''
> In general you declara an array like this:
>
> TYPE ArrayName [ array-size ] ;
>
> For instance:
>
> double array[256];
>
> or
>
> char array[256];
>
> In general since a standard string is an array of characters finished
> by a zero character there is no way of distinguishing it from an array
> of characters that is zero terminated.
>
> char array[] = { 'a', 'b', 0};
>
> This has the same representation as the string "ab".
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2011-11-08 04:07 -0500 |
| Message-ID | <4EB8F150.6704@mindspring.com> |
| In reply to | #12878 |
Nick Keighley wrote:
>
> On Nov 8, 8:14 am, jacob navia <ja...@spamsink.net> wrote:
> > Le 08/11/11 08:51, arnuld a écrit :
>
> > > I wrote my blog on Insertion Sort some time back and used words "Array of
> > > Integers" on that. I was told by someone that there is nothing like array
> > > of integers in C. C has array of objects only.
> >
> > > So how do we differentiate between array of integers and array of
> > > characters (not string constant) in communication if there is no such
> > > thing as array of integers ?
> >
> > You define an array of integers like this:
> >
> > int array[256];
> >
> > The person that told you that arrays of integers do not exist in C is
> > completely wrong.
>
> I agree. The array-of-T terminology has been around for an age. cdecl
> and such like use the terminology.
>
> Ah, from the standrard (draft '89)
>
> * An array type describes a contiguously allocated set of objects
> with a particular member object type, called the element
> type .Array
> types are characterized by their element type and by the number of
> members of the array. An array type is said to be derived from its
> element type, and if its element type is T , the array type is
> sometimes called ``array of T .'' The construction of an array type
> from an element type is called ``array type derivation.''
C90 also has:
6.1.2.5 Types
There are four signed integer types,
designated as signed char, short int, int, and long int.
For each of the signed integer types,
there is a corresponding (but different)
unsigned integer type
(designated with the keyword unsigned)
that uses the same amount of storage
(including sign information)
and has the same alignment requirements.
The type char, the signed and unsigned integer types,
and the enumerated types are collectively called integral types.
In C99,
6.2.5 Types
17 The type char, the signed and unsigned integer types,
and the enumerated types are collectively called integer types.
--
pete
[toc] | [prev] | [next] | [standalone]
| From | tom st denis <tom@iahu.ca> |
|---|---|
| Date | 2011-11-08 06:23 -0800 |
| Message-ID | <37c51614-8e33-47b1-a5e6-9e3e6fdcb401@o15g2000vbo.googlegroups.com> |
| In reply to | #12877 |
On Nov 8, 3:14 am, jacob navia <ja...@spamsink.net> wrote:
> In general since a standard string is an array of characters finished
> by a zero character there is no way of distinguishing it from an array
> of characters that is zero terminated.
>
> char array[] = { 'a', 'b', 0};
>
> This has the same representation as the string "ab".
Exception being you can then do
array[1] = 'c';
Whereas "ab"[1] = 'c' may work but isn't generally a good idea.
Tom
[toc] | [prev] | [next] | [standalone]
| From | "Scott Fluhrer" <sfluhrer@ix.netcom.com> |
|---|---|
| Date | 2011-11-08 10:08 -0500 |
| Message-ID | <1320764788.61130@rcdn-nntpcache-3> |
| In reply to | #12889 |
"Bradley K. Sherman" <bks@panix.com> wrote in message news:j9be9t$iag$1@reader1.panix.com... > In article > <37c51614-8e33-47b1-a5e6-9e3e6fdcb401@o15g2000vbo.googlegroups.com>, > tom st denis <tom@iahu.ca> wrote: >> ... >>Whereas "ab"[1] = 'c' may work but isn't generally a good idea. > > Why not? Looks like standard C to these old eyes. Yes, but what does it do? The Standard itself makes no promises whatsoever; examples of what a realistic compiler might do: - It does what you would naively expect it to - The write is ignored (although you probably need to paw through memory to distinguish this from the previous case) - It updates the string, and it also updates other instances of "ab" (and strings ending in "ab") elsewhere in the program - It crashes As Tom said, it's generally not a good idea... -- poncho
[toc] | [prev] | [next] | [standalone]
| From | Noob <root@127.0.0.1> |
|---|---|
| Date | 2011-11-08 16:25 +0100 |
| Message-ID | <j9bhk9$jh8$1@dont-email.me> |
| In reply to | #12889 |
Bradley K. Sherman wrote: > Tom wrote: > >> Whereas "ab"[1] = 'c' may work but isn't generally a good idea. > > Why not? Looks like standard C to these old eyes. String literals may not be modified.
[toc] | [prev] | [next] | [standalone]
| From | bks@panix.com (Bradley K. Sherman) |
|---|---|
| Date | 2011-11-08 15:39 +0000 |
| Message-ID | <j9bier$ot$1@reader1.panix.com> |
| In reply to | #12895 |
In article <j9bhk9$jh8$1@dont-email.me>, Noob <root@127.0.0.1> wrote:
>Bradley K. Sherman wrote:
>
>> Tom wrote:
>>
>>> Whereas "ab"[1] = 'c' may work but isn't generally a good idea.
>>
>> Why not? Looks like standard C to these old eyes.
>
>String literals may not be modified.
Quite right, I retract my question.
--bks
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2011-11-08 13:48 -0800 |
| Message-ID | <lnobwmcmkr.fsf@nuthaus.mib.org> |
| In reply to | #12895 |
Noob <root@127.0.0.1> writes:
> Bradley K. Sherman wrote:
>> Tom wrote:
>>> Whereas "ab"[1] = 'c' may work but isn't generally a good idea.
>>
>> Why not? Looks like standard C to these old eyes.
>
> String literals may not be modified.
Correction: The behavior of a program that attempts to modify a
string literal is undefined. The conclusion is the same: Don't
Do That. The difference is that the compiler isn't obligated to
diagnose the attempt (and it *could* "work").
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2011-11-09 19:34 -0800 |
| Message-ID | <lnaa84abvm.fsf@nuthaus.mib.org> |
| In reply to | #12911 |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> Keith Thompson <kst-u@mib.org> writes:
>>Correction: The behavior of a program that attempts to modify a
>>string literal is undefined.
>
> A string literal is part of the source code.
>
> The source code usually is not there when a program is running.
[...]
Yes, I was using a verbal shorthand. (And I've made enough similar
criticisms that it's a fair point.)
A string literal in source code corresponds to an array with static
storage duration that exists during program execution (C99 6.4.5).
The behavior of a program that attempts to modify that array is
undefined.
An example:
"hello"[0] = 'H';
A more realistic example:
void foo(char *s) { s[0] = 'h'; }
...
foo("hello");
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Nick Keighley <nick_keighley_nospam@hotmail.com> |
|---|---|
| Date | 2011-11-08 06:59 -0800 |
| Message-ID | <b33c3b62-9a4b-478d-9027-05627999bb9f@8g2000vbw.googlegroups.com> |
| In reply to | #12889 |
On Nov 8, 2:28 pm, b...@panix.com (Bradley K. Sherman) wrote: > In article <37c51614-8e33-47b1-a5e6-9e3e6fdcb...@o15g2000vbo.googlegroups.com>, > tom st denis <t...@iahu.ca> wrote: > >Whereas "ab"[1] = 'c' may work but isn't generally a good idea. > > Why not? Looks like standard C to these old eyes. it is undefined behaviour to modify a string literal. This allows compilers to share string representaions or place them in read-only memory.
[toc] | [prev] | [next] | [standalone]
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2011-11-08 22:48 +0100 |
| Message-ID | <j9c841$bpu$1@speranza.aioe.org> |
| In reply to | #12889 |
Le 08/11/11 15:23, tom st denis a écrit :
> On Nov 8, 3:14 am, jacob navia<ja...@spamsink.net> wrote:
>> In general since a standard string is an array of characters finished
>> by a zero character there is no way of distinguishing it from an array
>> of characters that is zero terminated.
>>
>> char array[] = { 'a', 'b', 0};
>>
>> This has the same representation as the string "ab".
>
> Exception being you can then do
>
> array[1] = 'c';
>
> Whereas "ab"[1] = 'c' may work but isn't generally a good idea.
>
> Tom
I said:
>> This has the same representation as the string "ab".
The same representation. Nothing else. Some compilers
put immediate strings constants in a read only section,
some not. The standard says those shouldn't be modified.
OK.
But what I said still holds:
>> char array[] = { 'a', 'b', 0};
>>
>> This has the same representation as the string "ab".
[toc] | [prev] | [next] | [standalone]
| From | Chad <cdalten@gmail.com> |
|---|---|
| Date | 2011-11-08 07:12 -0800 |
| Message-ID | <f5be4501-1991-4e7d-b64a-3421b093dc67@s35g2000pra.googlegroups.com> |
| In reply to | #12877 |
On Nov 8, 12:14 am, jacob navia <ja...@spamsink.net> wrote: > Le 08/11/11 08:51, arnuld a écrit : > > > I wrote my blog on Insertion Sort some time back and used words "Array of > > Integers" on that. I was told by someone that there is nothing like array > > of integers in C. C has array of objects only. > > > So how do we differentiate between array of integers and array of > > characters (not string constant) in communication if there is no such > > thing as array of integers ? > > You define an array of integers like this: > > int array[256]; > > The person that told you that arrays of integers do not exist in C is > completely wrong. > What about the following... http://67.40.109.61/torek/c/expr.html And I quote.. "Array objects have a special, fundamental rule in C. This rule is essentially arbitrary, and simply must be memorized. It falls out from a key fact: C does not have array values. (There is one exception to this, which I will save for later.) C does have array objects -- just the values are missing. For instance, int a[5]; declares an ordinary array containing five ints. Logically, the ‘value’ of this array ought to be the five int values stored in that array -- but it is not. Instead, the ‘value’ of the array is a pointer to the first element of that array. " The point being that, if I understand correctly, C does not have 'array of integers'. Instead, at least according to the former comp.lang.c regular on here, the language has 'array objects'. Chad
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2011-11-08 11:49 -0500 |
| Message-ID | <4EB95D9D.4ECE@mindspring.com> |
| In reply to | #12892 |
Chad wrote:
>
> On Nov 8, 12:14 am, jacob navia <ja...@spamsink.net> wrote:
> > Le 08/11/11 08:51, arnuld a écrit :
> >
> > > I wrote my blog on Insertion Sort some time back
> > > and used words "Array of
> > > Integers" on that. I was told by someone
> > > that there is nothing like array
> > > of integers in C. C has array of objects only.
> >
> > > So how do we differentiate between array of integers and array of
> > > characters (not string constant)
> > > in communication if there is no such
> > > thing as array of integers ?
> >
> > You define an array of integers like this:
> >
> > int array[256];
> >
> > The person that told you that arrays of
> > integers do not exist in C is
> > completely wrong.
> >
>
> What about the following...
>
> http://67.40.109.61/torek/c/expr.html
>
> And I quote..
>
> C does not have array values. (There is one
> exception to this, which I will save for later.)
Unless the case which is under discussion here and now,
happens to be the "one exception to this"
which he was saving for later,
he's wrong.
ISO/IEC ISO/IEC 9899:1999 (E)
6.7.8 Initialization
Semantics
8 An initializer specifies the initial value stored in an object.
16 Otherwise, the initializer for an object
that has aggregate or union type shall be a brace
enclosed list of initializers for the elements or named members.
> The point being that, if I understand correctly, C does not have
> 'array of integers'. Instead, at least according to the former
> comp.lang.c regular on here, the language has 'array objects'.
Given, as above:
int array[256];
then (array), is an "array of 256 int".
ISO/IEC 9899:1999 (E)
6.2.5 Types
17 The type char, the signed and unsigned integer types,
and the enumerated types are collectively called integer types.
20 An array type is said to be derived from its element type,
and if its element type is T, the array type is sometimes
called ‘‘array of T’’.
Since int is an integer type,
I don't see anything wrong
with calling (array) "an array of integers".
--
pete
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2011-11-08 12:13 -0500 |
| Message-ID | <4EB9631F.9090707@verizon.net> |
| In reply to | #12892 |
On 11/08/2011 10:12 AM, Chad wrote: > On Nov 8, 12:14 am, jacob navia <ja...@spamsink.net> wrote: ... >> The person that told you that arrays of integers do not exist in C is >> completely wrong. >> > > What about the following... > > http://67.40.109.61/torek/c/expr.html Note that at the top of that page, the author indicates use of non-standard language. He claims to be using 'object' to refer to what the standard calls an 'lvalue'. However, his actual use of the term doesn't support that claim; he frequently uses that term in ways where 'lvalue' wouldn't fit; in those cases he's actually using it in pretty much the same way the standard defines it. > "Array objects have a special, fundamental rule in C. This rule is > essentially arbitrary, and simply must be memorized. It falls out > from a key fact: C does not have array values. (There is one > exception to this, which I will save for later.) C does have array > objects -- just the values are missing. For instance, int a[5]; > declares an ordinary array containing five ints. Logically, the > ‘value’ of this array ought to be the five int values stored in that > array -- but it is not. Instead, the ‘value’ of the array is a > pointer to the first element of that array. " That paragraph fails to correctly explain what's going on in expressions like &a or sizeof a, but for most other expressions, it's close enough to be useful. He gives something closer to the correct rule farther down. The correct rule is in 6.3.2.1: "Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points to the initial element of the array object and is not an lvalue." > The point being that, if I understand correctly, C does not have > 'array of integers'. Instead, at least according to the former > comp.lang.c regular on here, the language has 'array objects'. The discussion has been about an "array of objects", not an "array object". An array object has sub-objects called elements. Those elements have a type, and an array of objects which have the type T are routinely referred to as an "array of T"; this usage is common in the standard itself. The first five examples I found of such usage were 6.2.5p20, footnote 36, 6.2.5p29, 6.3.2.1p3, and 6.5p6; there's many more. Nothing said on the page you're referring to is incompatible with that usage.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2011-11-08 21:45 +0000 |
| Message-ID | <0.cd3507adf735dc30bb32.20111108214558GMT.87fwhy47ah.fsf@bsb.me.uk> |
| In reply to | #12892 |
Chad <cdalten@gmail.com> writes:
> On Nov 8, 12:14 am, jacob navia <ja...@spamsink.net> wrote:
>> Le 08/11/11 08:51, arnuld a écrit :
>>
>> > I wrote my blog on Insertion Sort some time back and used words "Array of
>> > Integers" on that. I was told by someone that there is nothing like array
>> > of integers in C. C has array of objects only.
>>
>> > So how do we differentiate between array of integers and array of
>> > characters (not string constant) in communication if there is no such
>> > thing as array of integers ?
>>
>> You define an array of integers like this:
>>
>> int array[256];
>>
>> The person that told you that arrays of integers do not exist in C is
>> completely wrong.
>
> What about the following...
>
> http://67.40.109.61/torek/c/expr.html
>
> And I quote..
>
> "Array objects have a special, fundamental rule in C. This rule is
> essentially arbitrary, and simply must be memorized. It falls out
> from a key fact: C does not have array values. (There is one
> exception to this, which I will save for later.) C does have array
> objects -- just the values are missing. For instance, int a[5];
> declares an ordinary array containing five ints. Logically, the
> ‘value’ of this array ought to be the five int values stored in that
> array -- but it is not. Instead, the ‘value’ of the array is a
> pointer to the first element of that array. "
>
> The point being that, if I understand correctly, C does not have
> 'array of integers'. Instead, at least according to the former
> comp.lang.c regular on here, the language has 'array objects'.
No, that quote says that C has no array values, not that it has no
arrays. The point is not that an array of ints does not exist, but that
there is no way to denote it's value.
This is unlike the behaviour of many other types in C. Given
int i = 42;
struct point { int x, y; } p = { 1, 2 };
int ia[5] = { 1, 2, 3, 4, 5 };
the expression 'i' denotes the value of i, and the expression 'p'
denotes the value of p. You can't do this with an array. The
expression 'ia' does not denote the array named ia -- it is an
expression of type pointer to int.
It's a moot point whether the sub-expression 'ia' denotes the array in
the expression 'sizeof ia'. I'd go with "no" since the sub-expression
is not evaluated.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2011-11-08 16:48 -0500 |
| Message-ID | <4EB9A3BD.4040907@verizon.net> |
| In reply to | #12910 |
On 11/08/2011 04:45 PM, Ben Bacarisse wrote:
...
> This is unlike the behaviour of many other types in C. Given
>
> int i = 42;
> struct point { int x, y; } p = { 1, 2 };
> int ia[5] = { 1, 2, 3, 4, 5 };
>
> the expression 'i' denotes the value of i, and the expression 'p'
> denotes the value of p. You can't do this with an array. The
> expression 'ia' does not denote the array named ia -- it is an
> expression of type pointer to int.
>
> It's a moot point whether the sub-expression 'ia' denotes the array in
> the expression 'sizeof ia'. I'd go with "no" since the sub-expression
> is not evaluated.
How about in &ia?
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2011-11-08 14:25 -0800 |
| Message-ID | <ln39dyckvp.fsf@nuthaus.mib.org> |
| In reply to | #12913 |
James Kuyper <jameskuyper@verizon.net> writes:
> On 11/08/2011 04:45 PM, Ben Bacarisse wrote:
> ...
>> This is unlike the behaviour of many other types in C. Given
>>
>> int i = 42;
>> struct point { int x, y; } p = { 1, 2 };
>> int ia[5] = { 1, 2, 3, 4, 5 };
>>
>> the expression 'i' denotes the value of i, and the expression 'p'
>> denotes the value of p. You can't do this with an array. The
>> expression 'ia' does not denote the array named ia -- it is an
>> expression of type pointer to int.
>>
>> It's a moot point whether the sub-expression 'ia' denotes the array in
>> the expression 'sizeof ia'. I'd go with "no" since the sub-expression
>> is not evaluated.
>
> How about in &ia?
It refers to the array object. It doesn't refer to the value of that
object. (I maintain that it does have a value (see my other followup),
but it's not used here.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2011-11-08 22:42 +0000 |
| Message-ID | <0.0d6085b00f887a6f0045.20111108224237GMT.87aa8644o2.fsf@bsb.me.uk> |
| In reply to | #12913 |
James Kuyper <jameskuyper@verizon.net> writes:
> On 11/08/2011 04:45 PM, Ben Bacarisse wrote:
> ...
>> This is unlike the behaviour of many other types in C. Given
>>
>> int i = 42;
>> struct point { int x, y; } p = { 1, 2 };
>> int ia[5] = { 1, 2, 3, 4, 5 };
>>
>> the expression 'i' denotes the value of i, and the expression 'p'
>> denotes the value of p. You can't do this with an array. The
>> expression 'ia' does not denote the array named ia -- it is an
>> expression of type pointer to int.
>>
>> It's a moot point whether the sub-expression 'ia' denotes the array in
>> the expression 'sizeof ia'. I'd go with "no" since the sub-expression
>> is not evaluated.
>
> How about in &ia?
Well, it isn't a value, so it can't be an array value. Unadorned, the
term "value" does not include lvalues (see footnote 53 of 6.3.2.1 p1).
C does have lvalues of array types, but these are not some special kind
of value. In C, the "l" in "lvalue" is not a modifier. lvalues are
*expressions* and they get evaluated -- they are not themselves the
result of an evaluation (again, see 6.3.2.1 p1).
--
Ben.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c
csiph-web