Multiple Constants equal one When added.

Just starting out? Need help? Post your questions and find answers here.
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Multiple Constants equal one When added.

Post by GenRabbit »

Example 1;

Code: Select all

#testvalue1 = 98765
#testvalue2 = 98765
Define x.l
    x = #Testvalue1 + 1000
    x = #Testvalue2 + 2000
Example 2;

Code: Select all

#testvalue1 = 99765
#testvalue2 = 100765
Define x.l
    x = #Testvalue1
    x = #Testvalue2
Any chance that future updates will when compiling make those codesnippet generate equal code?
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Multiple Constants equal one When added.

Post by nco2k »

what?

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: Multiple Constants equal one When added.

Post by GenRabbit »

In both examples x becomes '99765' in the first line of code. Written 99765 or 98765 + 1000 shouldn't matter. So why different compiled code.
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Multiple Constants equal one When added.

Post by Bisonte »

I must also say : WHAT ?

I don't understand nothing of your question ...
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Multiple Constants equal one When added.

Post by Dude »

[Removed my assumption]
Last edited by Dude on Sat Oct 21, 2017 4:57 am, edited 1 time in total.
User avatar
Demivec
Addict
Addict
Posts: 4089
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Multiple Constants equal one When added.

Post by Demivec »

GenRabbit wrote:In both examples x becomes '99765' in the first line of code. Written 99765 or 98765 + 1000 shouldn't matter. So why different compiled code.
How do you know the code is compiled differently?

I compiled both and they are identical.

For fun, here is a commented version of the portions that were different (because the source in the comments is different):

Code: Select all

;Example 1
; 
; #testvalue1 = 98765
; #testvalue2 = 98765
; Define x.l
; x = #Testvalue1 + 1000
  MOV    dword [v_x],99765
; x = #Testvalue2 + 2000
  MOV    dword [v_x],100765
_PB_EOP_NoValue:
  PUSH   dword 0
_PB_EOP:
  CALL  _PB_EndFunctions
  PUSH   dword [PB_MemoryBase]
  CALL  _HeapDestroy@4
  CALL  _ExitProcess@4
_PB_EndFunctions:
  RET 

Code: Select all

;Example 2
; 
; #testvalue1 = 99765
; #testvalue2 = 100765
; Define x.l
; x = #Testvalue1
  MOV    dword [v_x],99765
; x = #Testvalue2
  MOV    dword [v_x],100765
_PB_EOP_NoValue:
  PUSH   dword 0
_PB_EOP:
  CALL  _PB_EndFunctions
  PUSH   dword [PB_MemoryBase]
  CALL  _HeapDestroy@4
  CALL  _ExitProcess@4
_PB_EndFunctions:
  RET
You'll notice that PureBasic folded (combined) the constants just as you suggested.
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: Multiple Constants equal one When added.

Post by GenRabbit »

I compiled both and then run a CRC32 check, and the CRC32 values of the two compiled files did not match. So I took it, they where different.
Thanks for taking the time to point it out. That I was wrong was good to hear. :)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Multiple Constants equal one When added.

Post by Dude »

GenRabbit wrote:I compiled both and then run a CRC32 check, and the CRC32 values of the two compiled files did not match.
That's just due to the time/date of the compile. To test, I compiled the same source twice, with only 10 seconds between compiles, and both exes had different CRC32 checksums.
Post Reply