Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2001:
[Freeciv-Dev] Re: (offtopic) C subscripts; was Re: Compiler-warnings
Home

[Freeciv-Dev] Re: (offtopic) C subscripts; was Re: Compiler-warnings

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "freeciv development list" <freeciv-dev@xxxxxxxxxxx>, "Gaute B Strokkenes" <gs234@xxxxxxxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: (offtopic) C subscripts; was Re: Compiler-warnings
From: "SamBC" <sambc@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 26 Jan 2001 16:05:56 -0000

Pontless message:

----- Original Message -----
From: "Gaute B Strokkenes" <gs234@xxxxxxxxxxxxxxxx>

>
> Incidentally, this means that [] is abelian:
>

This is the first time I have seen the new words I learnt on my first
year maths (degree) course used anywhere else. Makes me feel special to
understand it...

> int
> main (int argc, char *argv[])
> {
>   printf("The third letter of the alphabet is %c.\n", 2["ABC"]);
> }

Not sure if you're right though... I think some people are going odd on
the thing about pointer arithmetic/subscripts... given that an array
name and a pointer are the same thing, you get the same results,
excepting location in memory, with (excuse C++ code, point is the same
in C)

char* p = new char[50];
//initialise array
cout << p[20];
cout << *(p+20);

as you do with

char p[50];
//initialise array
cout << p[20];
cout << *(p+20);

and both should give unexpected results (or possibly errors) with

cout << p[-1];

as with

cout << *(p-1);

as well as with

cout << p[51];

and

cout << *(p+51);

Sory if someone else said this, or if I misunderstood... I'm a little
behind, a little out of practise, and a little tired...


SamBC









[Prev in Thread] Current Thread [Next in Thread]