Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #6092 > unrolled thread

offset 1 list indexing

Started byMichael Press <rubrum@pacbell.net>
First post2011-06-14 21:02 -0700
Last post2011-06-26 13:15 -0700
Articles 20 on this page of 56 — 19 participants

Back to article view | Back to comp.lang.c


Contents

  offset 1 list indexing Michael Press <rubrum@pacbell.net> - 2011-06-14 21:02 -0700
    Re: offset 1 list indexing Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-06-14 21:29 -0700
    Re: offset 1 list indexing Nobody <nobody@nowhere.com> - 2011-06-15 05:58 +0100
    Re: offset 1 list indexing Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-15 02:51 -0700
    Re: offset 1 list indexing jacob navia <jacob@spamsink.net> - 2011-06-15 12:01 +0200
      Re: offset 1 list indexing gwowen <gwowen@gmail.com> - 2011-06-15 03:55 -0700
    Re: offset 1 list indexing Mark Bluemel <mark_bluemel@pobox.com> - 2011-06-15 11:07 +0100
      Re: offset 1 list indexing Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-06-15 07:30 -0700
        Re: offset 1 list indexing Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-06-15 11:19 -0600
          Re: offset 1 list indexing James Kuyper <jameskuyper@verizon.net> - 2011-06-15 22:57 -0400
          Re: offset 1 list indexing Joseph Huber <joseph.huber@NOREPLY.web.de> - 2011-06-16 09:28 +0200
            Re: offset 1 list indexing Angel <angel+news@spamcop.net> - 2011-06-16 15:05 +0000
            Re: offset 1 list indexing jacob navia <jacob@spamsink.net> - 2011-06-24 01:14 +0200
        Re: offset 1 list indexing Michael Press <rubrum@pacbell.net> - 2011-06-15 15:33 -0700
      Re: offset 1 list indexing Michael Press <rubrum@pacbell.net> - 2011-06-15 15:28 -0700
        Re: offset 1 list indexing Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-15 23:34 -0400
          Re: offset 1 list indexing Michael Press <rubrum@pacbell.net> - 2011-06-15 21:42 -0700
            Re: offset 1 list indexing Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-16 08:18 -0400
              Re: offset 1 list indexing James Kuyper <jameskuyper@verizon.net> - 2011-06-16 08:32 -0400
                Re: offset 1 list indexing Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-06-16 06:29 -0700
                  Re: offset 1 list indexing James Kuyper <jameskuyper@verizon.net> - 2011-06-16 09:43 -0400
                Re: offset 1 list indexing Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-16 20:50 -0400
                  Re: offset 1 list indexing James Kuyper <jameskuyper@verizon.net> - 2011-06-17 08:56 -0400
                    Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-17 15:11 +0000
              Re: offset 1 list indexing Michael Press <rubrum@pacbell.net> - 2011-06-16 23:54 -0700
                Re: offset 1 list indexing Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-06-23 21:45 +0300
                  Re: offset 1 list indexing Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-25 09:30 -0700
                    Re: offset 1 list indexing pete <pfiland@mindspring.com> - 2011-06-25 13:10 -0400
                      Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-25 18:18 +0000
                        Re: offset 1 list indexing Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-25 15:56 -0400
                          Re: offset 1 list indexing James Kuyper <jameskuyper@verizon.net> - 2011-06-25 17:42 -0400
                            Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-26 04:15 +0000
                              Re: offset 1 list indexing pete <pfiland@mindspring.com> - 2011-06-26 01:51 -0400
                                Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-26 15:48 +0000
                                  Re: offset 1 list indexing pete <pfiland@mindspring.com> - 2011-06-27 00:30 -0400
                                Re: offset 1 list indexing Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-06-28 21:26 +0300
                                  Re: offset 1 list indexing pete <pfiland@mindspring.com> - 2011-06-28 23:36 -0400
                                    Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-29 15:28 +0000
                                      Re: offset 1 list indexing pete <pfiland@mindspring.com> - 2011-06-30 15:02 -0400
                              Re: offset 1 list indexing Ike Naar <ike@sverige.freeshell.org> - 2011-06-26 07:00 +0000
                                Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-26 15:20 +0000
                          Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-26 03:41 +0000
                            Re: offset 1 list indexing Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-26 08:51 -0400
                              Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-26 15:32 +0000
                                Re: offset 1 list indexing Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-26 11:48 -0400
                                  Re: offset 1 list indexing cri@tiac.net (Richard Harter) - 2011-06-26 16:43 +0000
                                  Re: offset 1 list indexing Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-06-28 21:30 +0300
                        Re: offset 1 list indexing Karl Malbrain <malbrain@yahoo.com> - 2011-06-28 14:13 -0700
                    Re: offset 1 list indexing Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-06-28 21:14 +0300
                      Re: offset 1 list indexing Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-29 01:14 -0700
    Re: offset 1 list indexing Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-15 07:21 -0400
    Re: offset 1 list indexing Shao Miller <sha0.miller@gmail.com> - 2011-06-15 10:09 -0400
      Re: offset 1 list indexing Michael Press <rubrum@pacbell.net> - 2011-06-15 15:38 -0700
    Re: offset 1 list indexing China Blue Dolls <chine.bleu@yahoo.com> - 2011-06-25 21:04 -0700
      Re: offset 1 list indexing Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-26 09:01 -0400
      Re: offset 1 list indexing Michael Press <rubrum@pacbell.net> - 2011-06-26 13:15 -0700

Page 1 of 3  [1] 2 3  Next page →


#6092 — offset 1 list indexing

FromMichael Press <rubrum@pacbell.net>
Date2011-06-14 21:02 -0700
Subjectoffset 1 list indexing
Message-ID<rubrum-E97163.21022514062011@news.albasani.net>
I want to index into a list using offset one indexing.
The obvious thing to do is make a pointer that points
one element before the list.

void work_on_stuff(int *offset0, int length)
{
    int offset1 = offset0 - 1;

    for(idx = 1; idx <= length; idx++)
    {
         ... offset1[idx] ...
    }
}

Is this likely to fail? Possible to fail?
Very unlikely to fail? Not guaranteed by the standard?

-- 
Michael Press

[toc] | [next] | [standalone]


#6093

FromMalcolm McLean <malcolm.mclean5@btinternet.com>
Date2011-06-14 21:29 -0700
Message-ID<bca94617-4663-46b0-881f-2b7346a1ea2c@j23g2000yqc.googlegroups.com>
In reply to#6092
On Jun 15, 7:02 am, Michael Press <rub...@pacbell.net> wrote:
> I want to index into a list using offset one indexing.
> The obvious thing to do is make a pointer that points
> one element before the list.
>
> void work_on_stuff(int *offset0, int length)
> {
>     int offset1 = offset0 - 1;
>
>     for(idx = 1; idx <= length; idx++)
>     {
>          ... offset1[idx] ...
>     }
>
> }
>
> Is this likely to fail? Possible to fail?
> Very unlikely to fail? Not guaranteed by the standard?
>
Moderately unlikely to fail. (I presume offset1 is an int * and this
is just a typo).

offset0 is a pointer to a valid chunk of memory. offset1 points to an
invalid chunk of memory before it. It may be occupied by another
variable, or it might be used for something else. The most likely
problem is that you have segmented memory and offset0 happens to be at
the start of a segment. offset1 might then turn into a wild pointer.
However a really sophisticated compiler with bounds checking might
trap offset1 as an illegal pointer. The standard makes no guarantees
that even storing offset0 - 1 will do what you intend. You're unlikely
to be running on either type of system, however.

[toc] | [prev] | [next] | [standalone]


#6094

FromNobody <nobody@nowhere.com>
Date2011-06-15 05:58 +0100
Message-ID<pan.2011.06.15.04.58.15.203000@nowhere.com>
In reply to#6092
On Tue, 14 Jun 2011 21:02:25 -0700, Michael Press wrote:

> I want to index into a list using offset one indexing.
> The obvious thing to do is make a pointer that points
> one element before the list.

> Is this likely to fail?

No.

> Possible to fail?

Yes.

> Very unlikely to fail?

Depends upon the platform. On a typical flat-memory architecture, it's
unlikely to fail, although I suppose that it could fail if the function is
inlined and the compiler is being especially clever.

> Not guaranteed by the standard?

AFAICT, it's okay by the standard so long as offset0 actually points at
least one element into an array. If it points to the first element of an
array, the behaviour is undefined.

Whether or not it works practice comes down to whether the architecture
cares about referencing invalid memory locations rather than actually
accessing them, e.g. segmented memory, trap representations, etc.

[toc] | [prev] | [next] | [standalone]


#6097

FromTim Rentsch <txr@alumni.caltech.edu>
Date2011-06-15 02:51 -0700
Message-ID<kfny613e81s.fsf@x-alumni2.alumni.caltech.edu>
In reply to#6092
Michael Press <rubrum@pacbell.net> writes:

> I want to index into a list using offset one indexing.
> The obvious thing to do is make a pointer that points
> one element before the list.
>
> void work_on_stuff(int *offset0, int length)
> {
>     int offset1 = offset0 - 1;
>
>     for(idx = 1; idx <= length; idx++)
>     {
>          ... offset1[idx] ...
>     }
> }
>
> Is this likely to fail? Possible to fail?
> Very unlikely to fail? Not guaranteed by the standard?

(Assuming 'offset0' actually points to the start of an array
rather than somewhere further on:)

Not guaranteed by the Standard, and a bad idea even though
currently it probably works in many (most?) compilers.

As compilers get more aggressive at code improvement, code
like this with undefined behavior gets more likely to cross
over into the compiler equivalent of the Neutral Zone.  If
and when that happens, most likely one of two things will
result:  one, the optimizer won't realize its assumptions
have been violated, and bogus code will be generated;  or
two, the optimizer _will_ realize its assumptions have been
violated, but will fall back to an ultra-conservative
position for code generation, preserving correctness but
sacrificing performance.

Neither of these possibilities is really good, but what's
worse is that they might start happening any time there is a
switch to a new compiler (or a different choice of compiler
options);  worse still, unless you are very careful you will
start to get bad results before realizing what has happened.
There's an old Polish proverb that says, Even if you are the
person who buried all the land mines, walking through a
minefield is no fun.


(TIA: "an old Polish proverb" isn't really a Polish
proverb - it's meant to be humorous for the cognoscenti.)

[toc] | [prev] | [next] | [standalone]


#6098

Fromjacob navia <jacob@spamsink.net>
Date2011-06-15 12:01 +0200
Message-ID<it9vtt$jus$1@speranza.aioe.org>
In reply to#6092
Le 15/06/11 06:02, Michael Press a écrit :
> I want to index into a list using offset one indexing.
> The obvious thing to do is make a pointer that points
> one element before the list.
>
> void work_on_stuff(int *offset0, int length)
> {
>      int offset1 = offset0 - 1;
>
>      for(idx = 1; idx<= length; idx++)
>      {
>           ... offset1[idx] ...
>      }
> }
>
> Is this likely to fail? Possible to fail?
> Very unlikely to fail? Not guaranteed by the standard?
>

Another evident way is to leave element zero unused and avoid
all problems... Why is that impossible?

[toc] | [prev] | [next] | [standalone]


#6100

Fromgwowen <gwowen@gmail.com>
Date2011-06-15 03:55 -0700
Message-ID<02e8acb6-1cd9-4782-86f3-8b961439a377@j28g2000vbp.googlegroups.com>
In reply to#6098
On Jun 15, 11:01 am, jacob navia <ja...@spamsink.net> wrote:

> Another evident way is to leave element zero unused and avoid
> all problems...

... as long as you remember to make all your arrays one-element-too-
large, to avoid falling of the end.

[toc] | [prev] | [next] | [standalone]


#6099

FromMark Bluemel <mark_bluemel@pobox.com>
Date2011-06-15 11:07 +0100
Message-ID<ita0gj$rcp$1@dont-email.me>
In reply to#6092
On 06/15/2011 05:02 AM, Michael Press wrote:
> I want to index into a list using offset one indexing.

Why?

[toc] | [prev] | [next] | [standalone]


#6109

FromMalcolm McLean <malcolm.mclean5@btinternet.com>
Date2011-06-15 07:30 -0700
Message-ID<37d77879-af78-4c7a-9029-027c7722109d@l18g2000yql.googlegroups.com>
In reply to#6099
On Jun 15, 1:07 pm, Mark Bluemel <mark_blue...@pobox.com> wrote:
> On 06/15/2011 05:02 AM, Michael Press wrote:
>
> > I want to index into a list using offset one indexing.
>
> Why?
>
Many language use 1-based arrays. So do mathematicians.

If you've ever tried fiddling with code written half in Fortran and
half in C you'll realise that sometimes 1-based array indexing can be
tempting.

--
MiniBasic - how to write a script interpreter
http://www.lulu.com/bgy1mm

[toc] | [prev] | [next] | [standalone]


#6113

FromJoe Pfeiffer <pfeiffer@cs.nmsu.edu>
Date2011-06-15 11:19 -0600
Message-ID<1bmxhjxba4.fsf@snowball.wb.pfeifferfamily.net>
In reply to#6109
Malcolm McLean <malcolm.mclean5@btinternet.com> writes:

> On Jun 15, 1:07 pm, Mark Bluemel <mark_blue...@pobox.com> wrote:
>> On 06/15/2011 05:02 AM, Michael Press wrote:
>>
>> > I want to index into a list using offset one indexing.
>>
>> Why?
>>
> Many language use 1-based arrays. So do mathematicians.
>
> If you've ever tried fiddling with code written half in Fortran and
> half in C you'll realise that sometimes 1-based array indexing can be
> tempting.

Giving new life to the old saying, "he can write FORTRAN in any
language".

[toc] | [prev] | [next] | [standalone]


#6130

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-06-15 22:57 -0400
Message-ID<itbreu$mpp$3@dont-email.me>
In reply to#6113
On 06/15/2011 02:30 PM, Keith Thompson wrote:
> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
>> Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
>>> On Jun 15, 1:07 pm, Mark Bluemel <mark_blue...@pobox.com> wrote:
>>>> On 06/15/2011 05:02 AM, Michael Press wrote:
>>>>> I want to index into a list using offset one indexing.
>>>>
>>>> Why?
>>>>
>>> Many language use 1-based arrays. So do mathematicians.
>>>
>>> If you've ever tried fiddling with code written half in Fortran and
>>> half in C you'll realise that sometimes 1-based array indexing can be
>>> tempting.
>>
>> Giving new life to the old saying, "he can write FORTRAN in any
>> language".
> 
> If I recall correctly, the book "Numerical Recipes in C" uses this trick
> to mimic the Fortran versions of the algorithms.

Yes. I've converted several of them to more idiomatic C; it's quite a pain.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#6137

FromJoseph Huber <joseph.huber@NOREPLY.web.de>
Date2011-06-16 09:28 +0200
Message-ID<itcbbg$1tv1$1@gwdu112.gwdg.de>
In reply to#6113
Joe Pfeiffer wrote:

> Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> 
>> On Jun 15, 1:07 pm, Mark Bluemel <mark_blue...@pobox.com> wrote:
>>> On 06/15/2011 05:02 AM, Michael Press wrote:
>>>
>>> > I want to index into a list using offset one indexing.
>>>
>>> Why?
>>>
>> Many language use 1-based arrays. So do mathematicians.
>>
>> If you've ever tried fiddling with code written half in Fortran and
>> half in C you'll realise that sometimes 1-based array indexing can be
>> tempting.
> 
> Giving new life to the old saying, "he can write FORTRAN in any
> language".

After 30 years of Fortran77, and 20 years of Fortran90+ there is no such 
thing as 1-based array indexing in Fortran.
It is only the DEFAULT lower bound 1 if nothing is specified in the 
declaration:
 integer array(0:N)
 integer array(-10:N)
 integer array(N) is equivalent integer array(1:N)

It's only C being inflexible!

-- 

Remove NOREPLY. from Email address.
Joseph Huber, http://www.huber-joseph.de

[toc] | [prev] | [next] | [standalone]


#6159

FromAngel <angel+news@spamcop.net>
Date2011-06-16 15:05 +0000
Message-ID<slrnivk6u2.ona.angel+news@pearlgates.net>
In reply to#6137
On 2011-06-16, Joseph Huber <joseph.huber@NOREPLY.web.de> wrote:
>
> After 30 years of Fortran77, and 20 years of Fortran90+ there is no such 
> thing as 1-based array indexing in Fortran.
> It is only the DEFAULT lower bound 1 if nothing is specified in the 
> declaration:
>  integer array(0:N)
>  integer array(-10:N)
>  integer array(N) is equivalent integer array(1:N)
>
> It's only C being inflexible!

Fortran was designed for complex calculations, C was designed to be a
general-purpose language. There is a limit to the number of features
that can (or should) be squeezed in, and N-based arrays are not
something that would see a lot of use in generic programs.

It's easy enough to implement an N-based array in C with accessor
functions or -macros, just more work. Likewise, there are probably things
that are easy to do in C but difficult or impossible in Fortran. It's a
matter of picking the right tool for the job.


-- 
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c

[toc] | [prev] | [next] | [standalone]


#6770

Fromjacob navia <jacob@spamsink.net>
Date2011-06-24 01:14 +0200
Message-ID<iu0hbq$5vf$1@speranza.aioe.org>
In reply to#6137
Le 16/06/11 09:28, Joseph Huber a écrit :
> Joe Pfeiffer wrote:
>
>> Malcolm McLean<malcolm.mclean5@btinternet.com>  writes:
>>
>>> On Jun 15, 1:07 pm, Mark Bluemel<mark_blue...@pobox.com>  wrote:
>>>> On 06/15/2011 05:02 AM, Michael Press wrote:
>>>>
>>>>> I want to index into a list using offset one indexing.
>>>>
>>>> Why?
>>>>
>>> Many language use 1-based arrays. So do mathematicians.
>>>
>>> If you've ever tried fiddling with code written half in Fortran and
>>> half in C you'll realise that sometimes 1-based array indexing can be
>>> tempting.
>>
>> Giving new life to the old saying, "he can write FORTRAN in any
>> language".
>
> After 30 years of Fortran77, and 20 years of Fortran90+ there is no such
> thing as 1-based array indexing in Fortran.
> It is only the DEFAULT lower bound 1 if nothing is specified in the
> declaration:
>   integer array(0:N)
>   integer array(-10:N)
>   integer array(N) is equivalent integer array(1:N)
>
> It's only C being inflexible!
>

1) integer array[0:N];

In C you allocate one more element and use 1 based indexing. The
zero element is left empty. Very easy

2) integer array[-10:N];

In C you set up a pointer to the 10th element and use that for indexing.

Yes, you CAN write fortran in any language, even C.

[toc] | [prev] | [next] | [standalone]


#6121

FromMichael Press <rubrum@pacbell.net>
Date2011-06-15 15:33 -0700
Message-ID<rubrum-0B1AFD.15333115062011@news.albasani.net>
In reply to#6109
In article 
<37d77879-af78-4c7a-9029-027c7722109d@l18g2000yql.googlegroups.com>,
 Malcolm McLean <malcolm.mclean5@btinternet.com> wrote:

> On Jun 15, 1:07 pm, Mark Bluemel <mark_blue...@pobox.com> wrote:
> > On 06/15/2011 05:02 AM, Michael Press wrote:
> >
> > > I want to index into a list using offset one indexing.
> >
> > Why?
> >
> Many language use 1-based arrays. So do mathematicians.
> 
> If you've ever tried fiddling with code written half in Fortran and
> half in C you'll realise that sometimes 1-based array indexing can be
> tempting.

Yes, but when translating Fortran offset-1 code 
to C, going to offset-0 loops is a big win. I
have done it, and the C code looks much better.
It becomes obvious in cascaded loops---many fewer,
or no 1's subtracted from array indices. 

It is in heaps that offset-1 arrays are neater.

-- 
Michael Press

[toc] | [prev] | [next] | [standalone]


#6119

FromMichael Press <rubrum@pacbell.net>
Date2011-06-15 15:28 -0700
Message-ID<rubrum-50B776.15281715062011@news.albasani.net>
In reply to#6099
In article <ita0gj$rcp$1@dont-email.me>,
 Mark Bluemel <mark_bluemel@pobox.com> wrote:

> On 06/15/2011 05:02 AM, Michael Press wrote:
> > I want to index into a list using offset one indexing.
> 
> Why?

Why not? But to humor you: heaps.

-- 
Michael Press

[toc] | [prev] | [next] | [standalone]


#6133

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-06-15 23:34 -0400
Message-ID<itbtln$4bk$1@dont-email.me>
In reply to#6119
On 6/15/2011 6:28 PM, Michael Press wrote:
> In article<ita0gj$rcp$1@dont-email.me>,
>   Mark Bluemel<mark_bluemel@pobox.com>  wrote:
>
>> On 06/15/2011 05:02 AM, Michael Press wrote:
>>> I want to index into a list using offset one indexing.
>>
>> Why?
>
> Why not? But to humor you: heaps.

     A few months ago, I offered heaps as an example of how some
programmers couldn't do simple index transformations, and were
unable to write zero-based implementations.

     Somewhat to my dismay, a few "programmers" in this group did
in fact maintain that it was "too difficult" or "too confusing" or
"too unnatural" to implement heaps in zero-based arrays.

     Ye.  Flipping.  Gods.

     "Programmers" who can't do simple arithmetic.

     Ye.  Flipping.  Gods.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#6135

FromMichael Press <rubrum@pacbell.net>
Date2011-06-15 21:42 -0700
Message-ID<rubrum-5D7959.21424215062011@news.albasani.net>
In reply to#6133
In article <itbtln$4bk$1@dont-email.me>,
 Eric Sosman <esosman@ieee-dot-org.invalid> wrote:

> On 6/15/2011 6:28 PM, Michael Press wrote:
> > In article<ita0gj$rcp$1@dont-email.me>,
> >   Mark Bluemel<mark_bluemel@pobox.com>  wrote:
> >
> >> On 06/15/2011 05:02 AM, Michael Press wrote:
> >>> I want to index into a list using offset one indexing.
> >>
> >> Why?
> >
> > Why not? But to humor you: heaps.
> 
>      A few months ago, I offered heaps as an example of how some
> programmers couldn't do simple index transformations, and were
> unable to write zero-based implementations.
> 
>      Somewhat to my dismay, a few "programmers" in this group did
> in fact maintain that it was "too difficult" or "too confusing" or
> "too unnatural" to implement heaps in zero-based arrays.
> 
>      Ye.  Flipping.  Gods.
> 
>      "Programmers" who can't do simple arithmetic.
> 
>      Ye.  Flipping.  Gods.

You've gone off the deep end. Get a grip;
or else tell me straight on I do not know
how to do simple arithmetic.

-- 
Michael Press

[toc] | [prev] | [next] | [standalone]


#6150

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-06-16 08:18 -0400
Message-ID<itcscc$9a1$1@dont-email.me>
In reply to#6135
On 6/16/2011 12:42 AM, Michael Press wrote:
> In article<itbtln$4bk$1@dont-email.me>,
>   Eric Sosman<esosman@ieee-dot-org.invalid>  wrote:
>
>> On 6/15/2011 6:28 PM, Michael Press wrote:
>>> In article<ita0gj$rcp$1@dont-email.me>,
>>>    Mark Bluemel<mark_bluemel@pobox.com>   wrote:
>>>
>>>> On 06/15/2011 05:02 AM, Michael Press wrote:
>>>>> I want to index into a list using offset one indexing.
>>>>
>>>> Why?
>>>
>>> Why not? But to humor you: heaps.
>>
>>       A few months ago, I offered heaps as an example of how some
>> programmers couldn't do simple index transformations, and were
>> unable to write zero-based implementations.
>>
>>       Somewhat to my dismay, a few "programmers" in this group did
>> in fact maintain that it was "too difficult" or "too confusing" or
>> "too unnatural" to implement heaps in zero-based arrays.
>>
>>       Ye.  Flipping.  Gods.
>>
>>       "Programmers" who can't do simple arithmetic.
>>
>>       Ye.  Flipping.  Gods.
>
> You've gone off the deep end. Get a grip;
> or else tell me straight on I do not know
> how to do simple arithmetic.

     Were you the person in that old thread who maintained that
heaps couldn't/wouldn't/shouldn't be implemented with anything
other than 1-based arrays?  I've forgotten.  But it's clear that
no important property of a heap depends on the raw numerical
values of the array indices: As long as you can compute the child
indices from the parent's index and vice versa, you can implement
a heap in an N-based array.

     And converting between a one-based index and an N-based
index *is* simple arithmetic.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


#6151

FromJames Kuyper <jameskuyper@verizon.net>
Date2011-06-16 08:32 -0400
Message-ID<itct4l$e0g$1@dont-email.me>
In reply to#6150
On 06/16/2011 08:18 AM, Eric Sosman wrote:
> On 6/16/2011 12:42 AM, Michael Press wrote:
>> In article<itbtln$4bk$1@dont-email.me>,
>>   Eric Sosman<esosman@ieee-dot-org.invalid>  wrote:
...
>>>       A few months ago, I offered heaps as an example of how some
>>> programmers couldn't do simple index transformations, and were
>>> unable to write zero-based implementations.
>>>
>>>       Somewhat to my dismay, a few "programmers" in this group did
>>> in fact maintain that it was "too difficult" or "too confusing" or
>>> "too unnatural" to implement heaps in zero-based arrays.
>>>
>>>       Ye.  Flipping.  Gods.
>>>
>>>       "Programmers" who can't do simple arithmetic.

No, programmers who WON'T perform simple arithmetic that unnecessarily
complicates their code. There's a big difference.

>>>       Ye.  Flipping.  Gods.
>>
>> You've gone off the deep end. Get a grip;
>> or else tell me straight on I do not know
>> how to do simple arithmetic.
> 
>      Were you the person in that old thread who maintained that
> heaps couldn't/wouldn't/shouldn't be implemented with anything
> other than 1-based arrays?  I've forgotten.  But it's clear that
> no important property of a heap depends on the raw numerical
> values of the array indices: As long as you can compute the child
> indices from the parent's index and vice versa, you can implement
> a heap in an N-based array.
> 
>      And converting between a one-based index and an N-based
> index *is* simple arithmetic.

That the transformation can be done, and even that it's easy, doesn't
mean that it's a good idea to perform it. That it's not necessarily a
transformation worth performing, means that it's just plain ridiculous
to misinterpret a refusal to perform it as indicating an inability to
perform it.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#6152

FromMalcolm McLean <malcolm.mclean5@btinternet.com>
Date2011-06-16 06:29 -0700
Message-ID<dd9a295c-64cb-4dcb-82d8-8effb8c87528@l2g2000prg.googlegroups.com>
In reply to#6151
On Jun 16, 3:32 pm, James Kuyper <jameskuy...@verizon.net> wrote:
>
> That the transformation can be done, and even that it's easy, doesn't
> mean that it's a good idea to perform it. That it's not necessarily a
> transformation worth performing, means that it's just plain ridiculous
> to misinterpret a refusal to perform it as indicating an inability to
> perform it.
>
If you're working with a mixture of C and Fortran you often have to
simultaneously convert between row-major to column-major, and offset
the arrays. It's too much.

[toc] | [prev] | [next] | [standalone]


Page 1 of 3  [1] 2 3  Next page →

Back to top | Article view | comp.lang.c


csiph-web