flat assembler
Message board for the users of flat assembler.

 Index > Main > Defining a structure
Author
jorido

Joined: 23 Jan 2017
Posts: 53
jorido 24 Jan 2017, 18:14
How to define a simple structure? I've seen this:

1)

Code:
```
struc point x, y, z
{
.x db x,
.y db y,
.z db z
}

```

2)
Code:
```  struct POINT
x db ?
y db ?
z db ?
ends
```

Questions:
a) is it struc or struct?
b) why { ... } in #1?
c) why arguments in #1?
d) or are these just 2 different ways to do basically the same thing?

And:

e) What's the most common convention for naming a structure: MY_STRUCT? Or MyStruct? Or my_struct? Or anything else?
24 Jan 2017, 18:14
Trinitek

Joined: 06 Nov 2011
Posts: 257
Trinitek 24 Jan 2017, 18:42
They're different things.

The first one, struc, is a directive that is provided by FASM. http://flatassembler.net/docs.php?article=manual#2.3.4

The second, struct, is a macro that is defined in win32a.inc. http://flatassembler.net/docs.php?article=win32#1.1
24 Jan 2017, 18:42
jorido

Joined: 23 Jan 2017
Posts: 53
jorido 24 Jan 2017, 19:29
Which one and when is used?
24 Jan 2017, 19:29
jorido

Joined: 23 Jan 2017
Posts: 53
jorido 25 Jan 2017, 07:38
What if I had a structre with 10 fields, would I have to list all of them as arguments?

Code:
```struc point a1, a2, a3, a4, a5, a6, a7, a8, a9, a10
{
.........

```
25 Jan 2017, 07:38
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20261
revolution 25 Jan 2017, 08:00
If you have a fixed number of arguments then, yes, you have to list them all if you need to initialise the values at the time of definition. If you have a variable number of arguments then you can use square brackets [args] to define the name and loop through the values with forward and reverse.
25 Jan 2017, 08:00
jorido

Joined: 23 Jan 2017
Posts: 53
jorido 25 Jan 2017, 09:11
>If you have a fixed number of arguments then, yes, you have to list them all if you need to initialise the values at the time of definition.

If I have a fixed number of them but don't want to initialise the values?

e) What's the most common convention for naming a structure: MY_STRUCT? Or MyStruct? Or my_struct? Or anything else?
25 Jan 2017, 09:11
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20261
revolution 25 Jan 2017, 10:19
jorido wrote:
If I have a fixed number of them but don't want to initialise the values?
Then just use a bare stuc with no defined parameters
jorido wrote:
e) What's the most common convention for naming a structure: MY_STRUCT? Or MyStruct? Or my_struct? Or anything else?
There is not really a common convention. Basically do whatever makes sense to you in your project. Your boss (if you have one) may dictate to you what naming conventions to use. They are arbitrary, but important.
25 Jan 2017, 10:19
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum