Liste des Groupes | Revenir à cl c |
On 18.04.2025 17:57, bart wrote:That's never going to happen. Only, possibly, if you have to port a 1-based algorithm to C, without risking the bugs that will creep in if you try and convert it to 0-based.On 18/04/2025 16:24, Kaz Kylheku wrote:It is perfectly fine to write your loops in "C" asOn 2025-04-17, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:>[...][...]
for (n = NUM_ENTRIES - 1; ...
That looks like another inconsistency in the syntax (and another error
opportunity).
>
Since the loop for upward and downward iterations between 0 and N-1
inclusve would be:
>
for (i = 0; i < N; ++i)
for (i = N-1; i >= 0; --i)
>
'N-1' is what I would have to write; it's odd that C people have write
it too. Unless perhaps you do this:
>
for (i = N; i-- > 0;)
>
Here you now have a genuine 2-part loop!
>
I guess this is C being 'flexible', in being able to reinvent for-loops
each time.
for (i = 1; i <= N; ++i)
for (i = N; i >= 1; --i)
(and access your array elements as [i-1] if you wish).
You should be aware that the problem you have here is *not* a "C"I can use 0-base arrays in my language, and yes, for loops to iterate over bounds could involve 0 and N-1:
"loop-problem", it's a problem of the low-level _"C" arrays_ you
have to use; they force you to define and use bounds of 0 and N-1
respectively if you want to use an array of N elements.
Les messages affichés proviennent d'usenet.