Recent

Author Topic: Weird problem with memory in Pascal.  (Read 15558 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Weird problem with memory in Pascal.
« Reply #15 on: November 15, 2010, 01:15:29 am »
Quote
Teacher has told us that arrays in Pascal are counting from one
Actually, it counts from whatever index you specify.
Quote
Weird, that program wasn't crashing without this - also when I was reading/writing data and causing out of range.
That's because, through a coincidence, the memory might be pointing to an address that is write/read-able by your program (another variable for instance), though it's out of the array range.

yarpen

  • New member
  • *
  • Posts: 9
Re: Weird problem with memory in Pascal.
« Reply #16 on: November 15, 2010, 10:57:06 am »
I know, but when I don't specify counting in array, it's from 1 to n.
I feel ashamed that I hasn't thought earlier about so easy and simple solution.
Anyway, thanks for your help.

OpenLieroXor

  • New Member
  • *
  • Posts: 38
Re: Weird problem with memory in Pascal.
« Reply #17 on: November 15, 2010, 07:11:01 pm »
I know, but when I don't specify counting in array, it's from 1 to n.
No. In your code you used dynamic arrays, which are always 0-based. Look here: http://wiki.freepascal.org/DYNAMIC_ARRAY
Quote
The index of a dynamic array is ZERO based, ie. it must be whittin the range from 0 to (Length-1). It is NOT possible to change this to a ONE based system.

mas steindorff

  • Hero Member
  • *****
  • Posts: 532
Re: Weird problem with memory in Pascal.
« Reply #18 on: November 15, 2010, 10:51:26 pm »
I know, but when I don't specify counting in array, it's from 1 to n.
I feel ashamed that I hasn't thought earlier about so easy and simple solution.
Anyway, thanks for your help.

when in doubt, let pascal figure it out

for i:= low(myarry) to high(myarray) do ....
windows 10 &11, Ubuntu 21+ - fpc 3.0.4, IDE 2.0 general releases

 

TinyPortal © 2005-2018