gus38
26th February 2007 14:16 UTC
Use of conditional compilation !if with &&
Hello,
I'm trying to use the conditional compilation !if with boolean comparison && but it seems not working well.
My code :
!define SECTIONDEF 0x0001
!insertmacro CreateSection SECTIONDEF "SECTIONNAME" "SECIDX"
!macro CreateSection SecDef SecText SecIdx
!echo "secname = ${${SecDef}}"
!if ${${SecDef}} && 0x0008
Section "!${SecText}" ${SecIdx} ; comparison true
!else
Section "${SecText}" ${SecIdx} ; comparison false
!endif
SectionIn RO 1 2
!macroend
I change the value of SECTIONDEF, but it always pass thru the true section code.
Do you have any idea ?
Thank you and sorry for my bad english
kichik
27th February 2007 19:44 UTC
What exactly are you trying to do? Double ampersand is a boolean operator not a binary operator. Your test only tells if both defines are not empty.
gus38
27th February 2007 20:38 UTC
Yes, thank you. :up:
I saw after posting this thread that it was only a boolean operator.:D
I have submitted a feature request on Sourceforge for a binary operator "&", in order to test only a bit on a define value.
kichik
27th February 2007 20:56 UTC
Thought that was you... You already have !define /math for that. It doesn't have bitwise AND, OR and XOR operators but I've added that for the next version.
gus38
27th February 2007 22:19 UTC
Just a precision : for !define with /math option, the value of define is the result of the operation ?
In my case, I'd like to check if some bits are present on a define value to create the section.
For example, if bit 1 and 4 of SECTIONDEF(=9) are set, I will declare my section like this :
Section "!SECTEXT"
SectionIn 1
This is in order to make different packages with only one common file with NSIS code and different headers file to define the behavior of sections (including the common file).
I hope you understand what I mean.
Thank you
kichik
27th February 2007 22:22 UTC
Then do:
!define /math result ${somedef} & 0x008
!if ${result} != 0
#...
gus38
27th February 2007 22:52 UTC
But I can't define two time "result", and I'd like to check different bit on different case.
I can use different define name, but if I use it in macro, it will create a lot of define.
The code I'd like to do :
!macro CreateSection SecDef SecText SecIdx
!if ${${SecDef}} == 0
Section "-${SecText}" ${SecIdx}
!else
!if ${${SecDef}} & 0x0008
Section "!${SecText}" ${SecIdx}
!else
Section "${SecText}" ${SecIdx}
!endif
!if ${${SecDef}} & 0x0001
SectionIn 1
!endif
!if ${${SecDef}} & 0x0002
SectionIn 2
!endif
!if ${${SecDef}} & 0x0004
SectionIn RO
!endif
!endif
!macroend
kichik
1st March 2007 19:04 UTC
Then !undef result right after you use it.
gus38
1st March 2007 19:57 UTC
I forgot it.
Thanks