flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Make FASM understand "C" typedefs

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 201
alorent
Hello,

I was wondering if it's possible to create a macro to fully understand C typedefs. I use some code that shares the same structure in a C module and in a FASM module, so it would be great if I can just define the typedef once. For example:

Code:
typedef struct sMyStruct
{
   DWORD   p1;
   BYTE       p2;
   char*      p3;
} MY_STRUCT;     


We could define in another file a possible EQU to make "char*" equal to "dd", DWORD -> dd, BYTE -> db, etc.

So, the above will generate in FASM:

Code:
MY_STRUCT struct
  p1 dd 0
  p2 db 0
  p3 dd 0
MY_STRUCT ends    


I'm not sure if it's possible or that format will colapse with FASM macros internals.

Thanks!
Post 15 Feb 2011, 18:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17352
Location: In your JS exploiting you and your system
revolution
Code:
  DWORD   p1;     
You need to convert that to something like:
Code:
 .p1 rd 1    
So a simple EQU can't do that. I think you would need to define DWORD as a macro.

As for char*, well you can make char a macro and have it search for the presence or absence of * and make the define accordingly.
Post 15 Feb 2011, 19:01
View user's profile Send private message Visit poster's website Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 201
alorent
revolution, thanks for the fast reply.

So, you think that it's imposible to make it in a way that C also understand the structure?

That is, if I change things for FASM, the C module might not understand the "typedef".

Thanks!
Post 15 Feb 2011, 19:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17352
Location: In your JS exploiting you and your system
revolution
I don't know about the impossibility or not. Actually, I was trying to offer suggestions to help you to get it working.
Post 15 Feb 2011, 19:09
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: 17352
Location: In your JS exploiting you and your system
revolution
Code:
macro DWORD var { .#var rd 1}
macro char param {match * y,param \{ ... \} }     
Post 15 Feb 2011, 19:11
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
Quote:
I was wondering if it's possible to create a macro to fully understand C typedefs.

i am wondering if it's possble to a C coder to understand the simplicity of asm data definitions.
Post 15 Feb 2011, 19:21
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
edfed wrote:
i am wondering if it's possble to a C coder to understand the simplicity of asm data definitions.


Me too. Laughing
Post 15 Feb 2011, 20:38
View user's profile Send private message Visit poster's website ICQ Number 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.