Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2003-10

General Question on code optimization...

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rainer Hantsch

Hello!

I wrote a unit for using MySQL a long time ago. It is basically the mysql unit, but with some modified/added functions to make life easier. But it is still procedural (currently not OOP).

Now I added some functions which allow me to access SQL data fields by their name and some other minor things.

Since this moment, I cannot compile old programs with this modified unit any more on an old SuSE 5.2 system with FPC 1.0.4, while they compile fine with the same compiler version on newer Linux versions! (-> Because newer FPC versions do not work on SuSE 5.2/5.3, I cannot upgrade to them.)

I tried to find out the reason, the problem is caused by some string definitions which seem to be used only by this new procedures when accessing fields by their name. (If somebody wants to have a look on the source, I can mail it to him, but I do not want to place here a long source by default.)

I could understand that the problems arise when I make use of this (new) functions, but shouldn't the compiler recognize when I do not use them and completely leave them out? In this case, compilation should still work, isn't that right?

If somebody can help, please do so. -- Thanks.

mfg

Ing. Rainer Hantsch

.---------------------------------------------------------------------. | \\|// Ing. Rainer HANTSCH - Hardware + Software | | (o o) Service - Support - WEB-Design und Programmierung | |--oOOo-(_)-oOOo------------------------------------------------------| | Ing. Rainer HANTSCH | mail: | | Khunngasse 21/20 | www: http://www.hantsch.co.at | | A-1030 Vienna | tel: +43-1-79885380 fax: +43-1-798853818 | | ** A u s t r i a ** | handy: +43-664-9194382 UID-Nr: ATU 11134002 | '---------------------------------------------------------------------'
Marco van de Voort
to Rainer Hantsch
Show quoted text 25 lines
Hello! I wrote a unit for using MySQL a long time ago. It is basically the mysql unit, but with some modified/added functions to make life easier. But it is still procedural (currently not OOP). Now I added some functions which allow me to access SQL data fields by their name and some other minor things. Since this moment, I cannot compile old programs with this modified unit any more on an old SuSE 5.2 system with FPC 1.0.4, while they compile fine with the same compiler version on newer Linux versions! (-> Because newer FPC versions do not work on SuSE 5.2/5.3, I cannot upgrade to them.) I tried to find out the reason, the problem is caused by some string definitions which seem to be used only by this new procedures when accessing fields by their name. (If somebody wants to have a look on the source, I can mail it to him, but I do not want to place here a long source by default.) I could understand that the problems arise when I make use of this (new) functions, but shouldn't the compiler recognize when I do not use them and completely leave them out? In this case, compilation should still work, isn't that right? If somebody can help, please do so. -- Thanks.

I think the best thing would be to find out what exactly hinders newer FPC versions, make a few mods and compile a matching version locally.

Rainer Hantsch
to Marco van de Voort

On Tue, 7 Oct 2003, Marco van de Voort wrote:
| I think the best thing would be to find out what exactly hinders newer | FPC versions, make a few mods and compile a matching version locally.

Are you talking about compiling a local FPC version, or about changing the mysql unit?
I never compiled my own FPC in the past and I am not really happy with the thought to start with that. :-/

But back to the basic question:

Shouldn't FreePascal automatically skip all code which is not required/used? Especially in a procedural environment it should be relatively easy to find out at compile time, which functions/procedures are used or not. So the compiler should be able -- especially when the unit source is present -- to build code which only contains that what is really used. Isn't it?

Instead, the compiler/linker/whatever seems to process the whole unit, regardless if portions of it are not used, and something drops over a problematic procedure even if this is not used at all! :-/

Does FPC include a whole unit with hundreds of procedures if I use only one (or none) of them? This would not be very smart!

I have absolutely no knowledge about how FPC internally works, which explains how good it works at all. (There simply is no need to fiddle around inside of it, it covers everything perfectly.) But there are some things which could (possibly) be made a little bit better... And one thing is that it could (possibly) resolve all dependices in a first pass and then only process that parts which are actually used.

mfg

Ing. Rainer Hantsch

.---------------------------------------------------------------------. | \\|// Ing. Rainer HANTSCH - Hardware + Software | | (o o) Service - Support - WEB-Design und Programmierung | |--oOOo-(_)-oOOo------------------------------------------------------| | Ing. Rainer HANTSCH | mail: | | Khunngasse 21/20 | www: http://www.hantsch.co.at | | A-1030 Vienna | tel: +43-1-79885380 fax: +43-1-798853818 | | ** A u s t r i a ** | handy: +43-664-9194382 UID-Nr: ATU 11134002 | '---------------------------------------------------------------------'
Peter Vreman
to Rainer Hantsch
Show quoted text 9 lines
Shouldn't FreePascal automatically skip all code which is not required/used? Especially in a procedural environment it should be relatively easy to find out at compile time, which functions/procedures are used or not. So the compiler should be able -- especially when the unit source is present -- to build code which only contains that what is really used. Isn't it?

This is done by the linker which is external. We can only create libraries that contain an object file for each procedure and variable

Show quoted text 8 lines
Instead, the compiler/linker/whatever seems to process the whole unit, regardless if portions of it are not used, and something drops over a problematic procedure even if this is not used at all! :-/ Does FPC include a whole unit with hundreds of procedures if I use only one (or none) of them? This would not be very smart!

There is smartlinking to create libraries that contain small object files. You can create the libraries with -CX. And you tell fpc to pass them to the linker with -XX

Marco van de Voort
to Rainer Hantsch: | I think the best thing would be to find out what exactly hinders newer | FPC versions,…
Show quoted text 6 lines
On Tue, 7 Oct 2003, Marco van de Voort wrote: | I think the best thing would be to find out what exactly hinders newer | FPC versions, make a few mods and compile a matching version locally. Are you talking about compiling a local FPC version, or about changing the mysql unit?

Having the _current_ version of FPC work on tha machine.

Show quoted text 9 lines
I never compiled my own FPC in the past and I am not really happy with the thought to start with that. :-/ But back to the basic question: Shouldn't FreePascal automatically skip all code which is not required/used? Especially in a procedural environment it should be relatively easy to find out at compile time, which functions/procedures are used or not.

In general yes, see Peter's answer.

But if you'd include mysql3 and mysql4 initialisation for both versions would be done, and you effectively would require (mysql3 AND mysql4) not (mysql3 OR mysql4)