Erik de Castro Lopo wrote:
O Plameras wrote:
I can modify my C-program to remove that problem in the ff. So,
as to whether a C-program is more prone to error relies on the
manner and style of coding and not intrinsic to C-language. Don't
you think ?
I don't think its specific to the C language, I think its intrinsic
to all looping operations in imperative programming.
All you've done is replace the for loop with a while loop. You are
still setting the start condition and the end condition for the
looping operation. These are things the compiler (or rather the
language) expect you to do.
In doing so I have a dramatic change in the way my program now behaves.
The problem with the for loop in the previous program is that every time
I change the size of my array I also need to change my for loop. In real
C-programs as we know this is where the problem lies, we change one
and not remembering to change the other.
In the modified program the size of array may be modified at will and
there is no need to remembering and change the loop. We may format
our array anywhere in the application and no need to change the loop.
This is where the power of C-pointer lies. If I am prepared and able,
as a programmer, to put good and compact pointer-arithmetic into my
programs I'd get better and concise C-programs. It is in the ability
of the C-programmer. He has a fine-grained control as to what should
happen.
By contrast, the O'caml mapi function automatically figures out
the start and end conditions from what it knows about the array.
This is what the modified C-program does with the concised while loop.
Erik
--
O Plameras
http://www.acay.com.au/~oscarp/tutor
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html