News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

structure with fixed data

Started by vid, November 10, 2007, 06:35:19 PM

Previous topic - Next topic

vid

another question: is it possible to stick fixed argument into structure, so that when instance of structure is being declared, there is no need to set it's value.

Something like this:


FILE_STREAM struct
  dd file_stream_vtab  ;fixed
  val1 dd ?
  val2 dd ?
FILE_STREAM ends

FILE_STREAM <1,2>


this way, "1" overwrites first dword. Is there some way to stick fixed data into structure, so that declaring instance can't overwrite it?
Problem with this is that in my library, people woud end up with something like this, to declare static object:


fs  MSTREAM <,,,,,,,read_buffer,10,,,,,buffer, buffer_size,>

and if they make mistake, they overwrite value which should be fixed, and there is quite ugly bug

TNick

I don't think so. In masm, at least. But you could tell people to use a macro for defining such structure, which would use the label that user wants along with values for members of that structure that you want to be changed. Maybe a flag to tell if the structure is in .DATA or in CONST section. But you may skip this, because user is expected to use the macro in either of these structures. Then, you just build your structure using both fixed and user provided values.

Nick

MichaelW

The only reasonable method I can see would be to  adopt a convention wherein a structure variable is always defined with no initializers, with any non-default initialization performed at run time using the variable and field name. Within your structure declaration you could use unnamed fields with a default initializer for any value than needed to be fixed. For complex structures like your MSTREAM example the normal method of specifying non-default initializers is too laborious and error prone. Initializing the fields by name makes it obvious.
eschew obfuscation

vid

I do support run time initialization, too.

So, I quess, I think static objects will not have extra suppot for MASM, besides this error-prone way. Maybe I will try to make macro solution later.

thanks