flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Virtual Confusion

Author
Thread Post new topic Reply to topic
MattBro



Joined: 08 Nov 2003
Posts: 37
MattBro
I am posting this really to help newbies and have no bug reports or complaints other than perhaps the description of the use of virtual in the manual should be clarified somewhat. Really I have nothing but praise for fasm ; it's been a godsend for my compiler development.

After writing hundreds of lines of fasm code I finally got around to delving into some of the fancier macro facilities such as struc and virtual. The fasm manual suggests the use of the virtual directive to create the equivalent of the C union directive and indeed it can be used to do this. However the manual is somewhat misleading about how this is done. After reading the manual I thought I could use virtual to create two pointers to the same place in memory something like this


virtual at chars
char0 db ?
char1 db ?
end virtual

chars db '01234'


With this code, char0, points to '0' and char1 points to '1'. This is actually preferrable to what I thought the manual was telling me, since it offers more flexibility. I had thought that everything in the virtual declaration would be forced to point to the value of the at operand, and hence, as in an actual union declaration, char0 and char1 would both point to the '0' byte

The correct way to do it is,


virtual at chars
char0 db ?
end virtual

virtual at chars
char1 db ?
end virtual


chars db '01234'


Just thought I'd offer this in case anyone else runs into this newbie mistake.

_________________
-- -------------------------------------------------------
"I am the Way and the Truth and the Light, no one comes to the Father except through me" - Jesus
---------------------------------------------------------
Post 21 Feb 2004, 19:38
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7106
Location: Slovakia
vid
first of all - virtual is not preprocessor feature, it is assembler feature

it was explained many times (once to me too), i think privalov should put explanation how it works to docs. It is really little confusing now
Post 22 Feb 2004, 20:15
View user's profile Send private message Visit poster's website AIM Address MSN Messenger 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-2019, Tomasz Grysztar.

Powered by rwasa.