flat assembler
Message board for the users of flat assembler.

Index > Main > struc and unions

Author
Thread Post new topic Reply to topic
arafel



Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
arafel
Is there any clean way to define an union in a struc (without using struct macros) ?

By 'clean' I mean something like this:

Code:
struc teststruc
{
union
.uval0 rb 1 
.uval1 rw 1
.uval2 rd 1
ends 
.val rd 1
}    


Following example should work i guess. But it looks kinda hackish since you need to specify size of each member in a comment.

Code:
struc teststruc 
{
; union start 
.uval0: ; rb 1 
.uval1: ; rw 1
.uval2 rd 1
; union end 
.val rd 1 
}    
Post 06 Oct 2006, 23:10
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
I recommend reading paragraph 2.3.4 Structures here. It doesn't specify unions as such, but it will get you pretty close to what you're after. I requires relearning how they are done with FASM.
Post 07 Oct 2006, 00:36
View user's profile Send private message Reply with quote
arafel



Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
arafel
yes, I read it already. Just hopped that there is some way to do this without resorting to macros.
...anyway now after browsing the sources a bit, it looks like there is no built-in support for unions. so macros are unavoidable. Sad
Post 07 Oct 2006, 01:47
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
I have to assume your inquisition is based on a C paradigm. ASM isn't C, therefore you have to invent what you want. However, I think the second example in that paragraph conveys a union of sorts. Don't consider a macro a bad thing, go with it, explore the possibility as a useful tool in order to meet your needs. C's abstration with unions is just that, an abstraction where you don't know the nuts and bolts employed to get the end result. Here you have the enviable ability to see/know exactly what is happening and understand the mechanics of it.

What is your aversion to macros?
Post 07 Oct 2006, 02:19
View user's profile Send private message Reply with quote
arafel



Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
arafel
union declaration merely allows one to refer to a location in a simple and efficient way. In this case there is no nuts and bolts to know or not know, really.
unions are no more an abstraction than let's say fasm's virtual or struc directive. In fact you can regard pretty much everything except the actual instruction mnemonics as an abstraction if judging by this assumption.
And anyway, sometime abstraction is a good thing (to a certain degree of course). Even in assemblers.

I never said I was against macros or considered them as a bad thing. However I do try avoid them when they are not really necessary, and imo in this case they aren't.
Post 07 Oct 2006, 03:54
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.

Powered by rwasa.