Inspired by (this more complicated post), wouldn't it be nifty if you could set initial structure values (of basic types) to chosen defaults in the definition?
I think structure defaults are a bad idea. What do you do if it's a public structure? With default offsets things could get unnecessarily complicated very quickly.
Just write an initialization function somewhere in your library and set the value yourself.
Mistrel wrote:I think structure defaults are a bad idea. What do you do if it's a public structure? With default offsets things could get unnecessarily complicated very quickly.
Well, then you wouldn't set defaults.
Just write an initialization function somewhere in your library and set the value yourself.
The point of this feature request is that it would do something PB users can't really do with current code: automatically set values for a structure when it is first created. You may create a structure from any number of different procedures or on any number of different codelines. If you want the structure to have default or automatic values, you would have to call a "defining procedure" manually from every place that the structure was created, and sometimes that just isn't practical (see my example above).
This feature request, if implemented, would get around that with a single line of code.
not a Structure hold values, but a Structured Element.
a Structure is just a descriptive offset, it's nothing to assign a value to.
thus, defining a default value when defining a structure is completely off meaning.
it would be like defining every LONGs should be 5, but every WORDs should be 23.
when you assign a starting value to a Variable, you assign it upon creation.
a more conveniant assigning method for Structured Elements upon creation would be nice.
but assigning values to a Structure itself is just physically incorrect.
I'm arguing for it. I think it would be very useful in some circumstances - as long as it was optional.
I'm not advocating it for general use. Of course not! But as I said, there are some circumstances where it just isn't practical to manually set the values for a structure's fields, and this feature would deal with that.
Seymour Clufley wrote:But as I said, there are some circumstances where it just isn't practical to manually set the values for a structure's fields, and this feature would deal with that.
Can you provide a real-world example where this would be the ideal solution for a problem? Perhaps some pseudo-code to reinforce the request?
Sorry for digging up this old thread, but +1 for the initial request.
Kaeru Gaman wrote:defining a default value when defining a structure is completely off meaning.
it would be like defining every LONGs should be 5, but every WORDs should be 23.
No, your comparison is wrong. All predefined data types (longs, words etc.) already have a default value, it's "0".
In a broader sense structures allow us to define our own data types. So it would really make sense to be able to define a default behavior as well.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
c4s wrote:Sorry for digging up this old thread, but +1 for the initial request.
Kaeru Gaman wrote:defining a default value when defining a structure is completely off meaning.
it would be like defining every LONGs should be 5, but every WORDs should be 23.
No, your comparison is wrong. All predefined data types (longs, words etc.) already have a default value, it's "0".
In a broader sense structures allow us to define our own data types. So it would really make sense to be able to define a default behavior as well.
c4s, structures have also default values, as everything is set to "0". It is more complex with structured pointers, as you are able to
point to uninitialized or already initialized memory.
kenmo wrote:Inspired by (this more complicated post), wouldn't it be nifty if you could set initial structure values (of basic types) to chosen defaults in the definition?
kenmo wrote:Inspired by (this more complicated post), wouldn't it be nifty if you could set initial structure values (of basic types) to chosen defaults in the definition?