Compiler related question

Blitz3D Forums/Blitz3D Programming/Compiler related question

_33(Posted 2008) [#1]
I was wondering, in Blitz3D (probably applies to the BlitzPlus compiler also), when we assign CONST labels, does the compiler replace all the labels with the values that are to be found in them? The reason I ask is because the labels are all to be found in the generated EXE.

Also, does it have any influence on performance when using CONST instead of placing the values directly?

example:
Const max% = 255
If meter > max Then
.........VS......
If meter > 255 Then



Stevie G(Posted 2008) [#2]
This has been discussed in the past - I'm fairly certain that the compiler definately replaces all instances of constants with their respective values. I guess this answers both questions.


Zethrax(Posted 2008) [#3]
As Stevie G said, constants are just placeholders for the values assigned to them. At compile time the constant identifiers are replaced by their assigned values, and the values are what gets compiled.

If you're finding the constant identifiers appearing in the compiled executable file, it could be for two reasons. Firstly, you may be compiling in debug mode, in which case a lot of extra information is probably being added to allow the debug routines to do meaningful error reporting. Secondly, the portable executable file format is used for both exe and dll (dynamic link library) files, and it contains extra info intended for use by dll files which is generally redundant in exe files. Some or all of this redundant info could probably be removed by stripping off the relocation section in the exe. You'll find a link to a free tool which can strip off the relocation section below.

http://www.jrsoftware.org/striprlc.php


_33(Posted 2008) [#4]
Oh goodie! Thanks Bill :) very nice explanation, will serve others I am sure.

Edit: When I try StripReloc on some blitz3d compiled test programs that I have, it strips 64K off the EXE. That is what I noticed. The blitz compiled program still works fine.

Edit2: Actually just noticed, with a hex editor, the labels that I found relative to my code are mostly function names. All variables and constants are nowhere to be found, before or after StripReloc. I must have dreamed this.