flat assembler
Message board for the users of flat assembler.

Index > Main > if ~defined blaa problem

Author
Thread Post new topic Reply to topic
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 08 Aug 2006, 03:04
What's wrong with this?
Code:
if ~defined GetFilePart
        extrn '_GetFilePart@8' as GetFilePart:dword
end if    


I'm getting this when compiling one of the sources including the .inc file where the code above is in:
Quote:
flat assembler version 1.67.6 (567458 kilobytes memory)
error: code cannot be generated.
*** Error code: 255 ***


All the files including that seem to be doing this, bug in if ~defined?

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 08 Aug 2006, 03:04
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
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 Razz

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
    
Post 08 Aug 2006, 08:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
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 Razz
Post 08 Aug 2006, 09:58
View user's profile Send private message MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
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.    
This can be fixed with a new macro.
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.    
This has the advantage of eliminating the ..HERE variable and also means we don't actually need a macro to define a local label, so the code can be pure assembly without the wrapper.
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.    
Post 30 May 2024, 06:04
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4043
Location: vpcmpistri
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    
... it seems to cover the same cases?

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 30 May 2024, 14:58
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
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
Post 30 May 2024, 15:11
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4339
Location: Now
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)
Post 30 May 2024, 22:33
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
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    
Because macros do not care about if/end if
Post 31 May 2024, 03:20
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4339
Location: Now
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...
Post 03 Jun 2024, 11:59
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
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.
Post 03 Jun 2024, 12:15
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4339
Location: Now
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.

Rolling Eyes
Image
Post 03 Jun 2024, 20:14
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.