Jump to content




Recent Topics

Recent Status Updates

  • Photo
      12 Sep
    FacetiousTurtle33

    Just joined. Really enjoy this sight. Excited to become a great programmer, and helper.

    Show comments (2)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

Turbo to Free Pascal

pascal

  • Please log in to reply
1 reply to this topic

#1 Benny Brodda

Benny Brodda

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 22 February 2012 - 02:58 AM

Hi, My name is Benny and I'm involved in a project aiming at providing systems for trademark handling, and my part is to convert a central program system for this project, now written in TP, into FP. My specific problem just now is as follows:
In TP I declare as global variables (i.e. in the VAR section b4 all procedures and functions) 5 bytes, say 'a, b, c, d, e: byte'. In TP these bytes are placed in consecutive addresses by the compiler, which means that I can use MOVE to move these variables in and out from, say, a (9 X 5) array of bytes, which saves a lot of boring code writing and improves speed a lot. In FP this doesnt work, the variables seem not to be placed consecutively in the memory. However, if I declare them as belonging to a (packed) Record the Move trick works just fine, but, as it happens, I haven't found a way to addres these bytes individually; they seem to be invisible from the rest of the program. In TP I can use a pointer, say Sptr, to this record and write 'Sptr^b', if I will reach the byte 'b', for instance. I have tried this in FP, but the compiler doesn't allow it. How do I do this?
Benny
  • 0

#2 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,318 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 23 February 2012 - 03:04 AM

Hi, My name is Benny and I'm involved in a project aiming at providing systems for trademark handling, and my part is to convert a central program system for this project, now written in TP, into FP. My specific problem just now is as follows:
In TP I declare as global variables (i.e. in the VAR section b4 all procedures and functions) 5 bytes, say 'a, b, c, d, e: byte'. In TP these bytes are placed in consecutive addresses by the compiler, which means that I can use MOVE to move these variables in and out from, say, a (9 X 5) array of bytes, which saves a lot of boring code writing and improves speed a lot. In FP this doesnt work, the variables seem not to be placed consecutively in the memory.


The cause of your problem is that current compiler is optimizing your codes. 32 bit data is much easier and faster to handle in 32bit system. So your one byte data will be stored in an area of 4bytes. No wonder that moving the bytes giving unexpected result. Because now you are moving 1byte into the space of 4bytes.

You could try to turn off any optimization options in FPC. I don't know exactly which, but in Delphi you could try adjust Record Field Alignment to off or to byte

Anyway, what you are doing is bad. Since it depends on the internal behavior of your compiler. About speed, with current power of computers, you will find insignificant difference.

However, if I declare them as belonging to a (packed) Record the Move trick works just fine, but, as it happens, I haven't found a way to addres these bytes individually; they seem to be invisible from the rest of the program. In TP I can use a pointer, say Sptr, to this record and write 'Sptr^b', if I will reach the byte 'b', for instance. I have tried this in FP, but the compiler doesn't allow it. How do I do this?
Benny


Can you paste your code related with this packed record. It should be working, unless you have missed something.
  • 0





Also tagged with one or more of these keywords: pascal