Velocity Reviews > Array of Integers ?

Array of Integers ?

arnuld
Guest
Posts: n/a

 11-08-2011
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

Ike Naar
Guest
Posts: n/a

 11-08-2011
On 2011-11-08, arnuld <(E-Mail Removed)> 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.

jacob navia
Guest
Posts: n/a

 11-08-2011
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".

Nick Keighley
Guest
Posts: n/a

 11-08-2011
On Nov 8, 8:14*am, jacob navia <(E-Mail Removed)> 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".

Malcolm McLean
Guest
Posts: n/a

 11-08-2011
On Nov 8, 9:51*am, arnuld <(E-Mail Removed)> 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.
>

C has several integer types, "int" is meant to be the default signed
type and is the "natural integer type" for the machine, which usually
means that it's the same width as a register.

An "object" in C is either an atomic type or a structure or, rarely,
an array. Objects are contiguous in memory. So an array of integers,
whether they be ints, longs, shorts or whatever, is an array of
objects. It's often useful to treat an array as an array of blind
objects, by passing in a void * to the start of the array and the
object width and count. memcpy(), memmove(), qsort() just treat arrays
as lists of bytes, and can be used on ints, doubles, structures, or
any object type.

--
http://www.malcolmmclean.site11.com/www

James Kuyper
Guest
Posts: n/a

 11-08-2011
On 11/08/2011 02:51 AM, arnuld 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 ?

Ignore this person. "Array of integers" is nothing more or less than
shorthand for "array of objects of integer type"; the distinction he's
trying to make is pointless.
--
James Kuyper

tom st denis
Guest
Posts: n/a

 11-08-2011
On Nov 8, 3:14*am, jacob navia <(E-Mail Removed)> 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

Guest
Posts: n/a

 11-08-2011
In article <(E-Mail Removed)>,
tom st denis <(E-Mail Removed)> wrote:
> ...
>Whereas "ab"[1] = 'c' may work but isn't generally a good idea.

Why not? Looks like standard C to these old eyes.

--bks

Nick Keighley
Guest
Posts: n/a

 11-08-2011
On Nov 8, 2:28*pm, (E-Mail Removed) (Bradley K. Sherman) wrote:
> In article <(E-Mail Removed)..com>,
> tom st denis *<(E-Mail Removed)> 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.

Guest
Posts: n/a

 11-08-2011
On Nov 8, 12:14*am, jacob navia <(E-Mail Removed)> 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.
>

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'.