flat assembler
Message board for the users of flat assembler.
Index
> Main > if ~defined blaa problem |
Author |
|
vid 08 Aug 2006, 08:44
I can't believe this still isn't in the FAQ. Tomasz, place it there.
"defined" operator means "defined anywhere in source", not "defined previously in source" like in C. and "if a is not defined then a is defined" is paradox, there is no way to interpret it, and so code cannot be generated if you want "defined previously" then i suggest this macro: Code: ;============================================== ;ifndef ;desc: checks if expression (usually symbol) is not "defined" previously ; in code (not in whole file, like with "if ~defined expr") ;args: expr - any expression acceptable as argument to "defined" operator ;note: end block with "end if", just like any "if" command macro ifndef expr* { local ..HERE if defined ..HERE | ~ defined expr ..HERE = 1 } ifndef GetFilePart extrn '_GetFilePart@8' as GetFilePart:dword end if |
|||
08 Aug 2006, 08:44 |
|
okasvi 08 Aug 2006, 09:58
heh, thanks for the macro
I did read manual about if ~defined but I think I got it wrong |
|||
08 Aug 2006, 09:58 |
|
revolution 30 May 2024, 06:04
To support using "if used ..." a new macro is needed. For example this code below fails:
Code: macro ifndef expr* { local ..HERE if defined ..HERE | ~ defined expr ..HERE = 1 } ; some code that wants to override the default definition below if used y y db 1 end if ; default implementation if not provided by any other source ifndef y if used y y db 0 end if end if mov eax,y Code: flat assembler version 1.73.31 (16384 kilobytes memory) ifndef.asm [15]: y db 0 processed: y db 0 error: symbol already defined. Code: macro ifndef expr* { if ~ defined expr | expr = $ } ; some code that wants to override the default definition below if used y y db 1 end if ; default implementation if not provided by any other source ifndef y if used y y db 0 end if end if mov eax,y Code: flat assembler version 1.73.31 (16384 kilobytes memory) 2 passes, 7 bytes. Code: ; some code that wants to override the default definition below if used y y db 1 end if ; default implementation if not provided by any other source if (~ defined y | y = $) & used y y db 0 end if mov eax,y Code: flat assembler version 1.73.31 (16384 kilobytes memory) 2 passes, 7 bytes. |
|||
30 May 2024, 06:04 |
|
bitRAKE 30 May 2024, 14:58
If we are using $ to anchor the label and the size is non-zero, what situation is not covered by:
Code: if used y & y = $ y db 0 end if _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
30 May 2024, 14:58 |
|
revolution 30 May 2024, 15:11
It fails when the usage is above the definition.
Code: ; some code that wants to override the default definition below ;if used y ; y db 1 ;end if mov eax,y ; default implementation if not provided by any other source if used y & y = $ y db 0 end if Code: flat assembler version 1.73.31 (16384 kilobytes memory) ifdef.asm [6]: mov eax,y processed: mov eax,y error: undefined symbol 'y'. Last edited by revolution on 28 Jul 2024, 20:04; edited 1 time in total |
|||
30 May 2024, 15:11 |
|
edfed 30 May 2024, 22:33
Code: ;blafoobar: if ~definite BLA include 'bla.inc' if ~defined FOO include 'bar.inc' else include 'foo.inc' end if BLA: end if this code works fine to make a define once (definite) equivalent to an include guard (vc++ pragma once), and to make a binary switch (defined) |
|||
30 May 2024, 22:33 |
|
revolution 31 May 2024, 03:20
If the included files have macros that overlap then you can experience problems.
Code: ; file_1 macro x { ... } ; file_2 macro x { ... } ; ... if thing include 'file_1' ; defines x else include 'file_2' ; defines alternative x, right? NO!!! this ALWAYS defines x here, and overrides the x from flie_1 end if |
|||
31 May 2024, 03:20 |
|
edfed 03 Jun 2024, 11:59
OMG! that's annoying
Code: ;FOO: if ~definite BLA macro X { display 'A' } if defined FOO macro X { display 'B' } else macro X { display 'C' } end if BLA: end if X now, time to switch macros from outside of them... |
|||
03 Jun 2024, 11:59 |
|
revolution 03 Jun 2024, 12:15
Doesn't work the way one might expect. if is ignored by the macro definitions.
To optionally define macros you need to use match, irp or rept or another macro (or struc) in some comination with equ or define. None of the assembly pass constructs can ever affect how macros are defined. |
|||
03 Jun 2024, 12:15 |
|
edfed 03 Jun 2024, 20:14
totally counter intuitive from the human semantic point of view, but yes, as macro are in preprocessor, all the rest are ignored...
time to play with matches again then. |
|||
03 Jun 2024, 20:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.