Closed lundmark closed 5 years ago
Wow the formatting of that went to shit :( Sorry about that.
Here's a test-case that you can drop into unittest.tld:
"struct_with_defaults" : {
"members" : [
{ "name" : "some_variable_1", "type" : "uint32" "default" : 777 },
{ "name" : "some_variable_2", "type" : "fp32", "default" : 0.5 },
{ "name" : "some_variable_3", "type" : "fp32", "default" : 0 },
{ "name" : "some_variable_4", "type" : "fp32", "default" : 20 },
{ "name" : "some_variable_5", "type" : "fp32", "default" : 0.1 }
]
},
"struct_with_inline_array_of_defaults" : {
"members" : [
{ "name" : "dummy1", "type" : "struct_with_defaults[8]" },
{ "name" : "dummy2", "type" : "struct_with_defaults[4]", "default" : [] },
{ "name" : "dummy3", "type" : "struct_with_defaults[6]", "default" : [ { "some_variable_4" : 0 }, { "some_variable_4" : 1 }, { "some_variable_4" : 2 } ] }
]
}
preferably all three of those should work.
As a workaround until I get this going you could try to just initialize it as
{ "name" : "dummy2", "type" : "struct_with_defaults[4]", "default" : [{},{},{},{}] }
I think, without trying it, that that should work already.
this one I still think should be an error as you havn't specified that it has a default-value, i.e. it need a value. Also to get this to work we would need to store default-values for all inline-arrays in the tld and that seems wasteful.
{ "name" : "dummy1", "type" : "struct_with_defaults[8]" }
Yes that probably works (trying it now).
There are situations where you have for example, an inline-char-array of a certain size (say 256) and you want it to be default zeroed... how would we do that reasonably? It's not very nice to have a default with 256 0's in it.
I'll fix default of pods to memset(0).
I'll fix default of pods to memset(0). Observe that the fix that is coming will also default all non-set values in an inline-array when just setting them, not only in a "default". Is that a good thing, I'm not really sure yet :)
I think that's a really good thing. IF that would ever be a problem, I think that a flag on that member can be used to turn that feature off.
First revision submitted... report bugs with the feature as new bugs please, I'll close this :)
For example if you have a type a, with members b, c, d who all have defaults. Then you want to have an inline-array k of n amount of a and want that to be default-initialized and you're going to run into issues. You'll need to define default for k as n amounts of a with all of its members set to default values.
Can't get more abstract than that in the example. So here we go:
It would be a LOT nicer if this was possible: