flat assembler
Message board for the users of flat assembler.

Index > Windows > fasm C-compatible syntax typedef macro

Author
Thread Post new topic Reply to topic
goldenspider



Joined: 16 May 2011
Posts: 38
goldenspider
According to the post using types defined with EQU in structures
i update the typedef macro and work OK.

Code:
macro macro@typedef base,[type] 
{ 
    forward
    struc type [v] 
    \{ 
        \common match any, v \\{ . base v \\} 
            match , v \\{ . base ? \\}
    \} 
    macro type [v] 
    \{ 
        \common match any, v \\{ base v \\} 
            match , v \\{ base ? \\}
    \}
    virtual at 0
      base ?
      sizeof.#type=$
    end virtual
} 

macro typedef [statement] 
{ 
    common
    match gs@base gs@type,statement
    \{
        macro@typedef gs@base,gs@type
    \}
}
    


for example:
Code:
typedef dd SDWORD
typedef SDWORD DWORD,INT32,LONG
typedef db CHAR,BYTE

_WIN64 equ FALSE

match =TRUE ,_WIN64{typedef dq PVOID}
match =FALSE,_WIN64{typedef dd PVOID} 

typedef PVOID HANDLE,PSTR,PWSTR
;....................
;struct define
struc point x,y
{
  .:
  .x SDWORD x
  .y INT32 y
  .size = $ - .
}

struct SIZE
  cx LONG
  cy LONG
ends

typedef SIZE newSIZE
;....................
;Data define

m1 SDWORD 12,13,14,sizeof.DWORD
m2 INT32 12,13,14,sizeof.INT32
my point 7,my.size

INT32
m3 INT32 
;....................
;local define

proc WindowProc uses ebx esi edi,hwnd,wmsg,wparam,lparam
    local hDC:HANDLE
    local mySize:newSIZE
    ...
    


Typical windows data types:
Code:
_WIN64  equ FALSE    ;(or TRUE)

typedef db  UINT8 ,INT8 ,BYTE ,CHAR,UCHAR
typedef dw  UINT16,INT16,WORD ,WCHAR
typedef dd  UINT32,INT32,DWORD,LONG,ULONG
typedef dq  UINT64,INT64,QWORD,LONGLONG,ULONGLONG

typedef DWORD BOOL,long,int,HRESULT

match =TRUE ,_WIN64{typedef dq PVOID}
match =FALSE,_WIN64{typedef dd PVOID} 

typedef PVOID HANDLE,PSTR,PWSTR,LPVOID
    


Description:
Download
Filename: DDraw.inc
Filesize: 87.44 KB
Downloaded: 56 Time(s)

Post 05 Apr 2013, 14:40
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
goldenspider
That's a simple and concise feature, so don't make it more complicated, than it should be. Wink
Code:
macro macro@typedef base,[type]  
{  
    forward 
        struc type [v=?] \{ \common . base v \}
        macro type [v=?] \{ \common base v \}
        virtual at 0 
            base ? 
            sizeof.#type=$ 
        end virtual 
}    

Btw. I'd rather prefer a single macro, i.e. no multiplication of entities beyond necessity:
Code:
macro typedef [statement*]
{
    common match gs@base gs@type,statement
    \{
        irp type,gs@type
        \\{
            struc type [v=?] \\\{ \\\common . gs@base v \\\}
            macro type [v=?] \\\{ \\\common gs@base v \\\}
            virtual at 0
                gs@base ?
                sizeof.\\#type=$
            end virtual
        \\}
    \}
}    

_________________
Faith is a superposition of knowledge and fallacy
Post 05 Apr 2013, 23:43
View user's profile Send private message Reply with quote
goldenspider



Joined: 16 May 2011
Posts: 38
goldenspider
aha,I_inc, I appreciate your macro. ^_^ But [v=?] is new feature.

version 1.70 (Apr 17, 2012):
[+] Macroinstruction argument now can have default value, defined with "="
symbol followed by value after the argument name in definition.
------------------
The top macro is also applicable to version 1.67 and above.
Post 06 Apr 2013, 02:30
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
goldenspider
Sure, you are right. But considering, that fasm is small, free, portable and retains backward compatibility, I see no reason to support older versions by introducing more complexity. IMHO older versions support is only eligible if no trade off is needed to achieve that.

_________________
Faith is a superposition of knowledge and fallacy
Post 06 Apr 2013, 13:52
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.