-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value Instance does not accept type attribute (despite the documentation's assertion) #463
Comments
There is a pretty bad workaround: instances:
a:
pos: 0
type: "b(c)" Unfortunately it won't help you, you can't convert a value instance into a user-controlled-size built-in type (except bool) for now. Internally nearly all the integer value instances are CalcIntType. And they are transformed into a 32-bit int (BTW, @GreyCat, why not 64-bit?) See #127 about it. |
Unfortunately, KSY reference is very outdated and needs major revamp. "Instance spec" it describes is actualy a "parse instance", not "value instance". This question was indeed raised in several different contexts quite a few times before:
This particular problem is somewhat more sophisticated than you have might expect. Namely, if we'll be talking about The simple answer is: we can't tell, as it is very dependent on target-language (and, sometimes, even implementation-dependent). KS expressions are built with this in mind, introducing It looks like that what you want in your particular case is indeed typecasting, not "setting a type of value instance" (as this is happening automatically). Typecasting would have been used as |
Actually, I've implemented it right now. Stuff like
should yield static_cast<uint16_t>(a + b) in C++. |
Thanks for the historical references (clearly, you are better at working the search mechanism than I am!). As for the ambiguity of the type resulting from the expression, that's the exact problem that I was hoping to solve by specifying the Using a typecast in the instance |
You can use unstable releases right away. We publish packages for Debian and Windows. |
Problem seems to be fixed, will be part of 0.9 release. |
[My apologies if this has already been reported -- the obvious search terms turned up more issues than I could check -- maybe I'm just feeble.]
I have a pile of KSY files. They contain a variety of type definitions, but they all have a few which are common, where "common" means, same name and fields with the same names (but, possibly in a different order or with different sizes, etc.). In particular, one type definition has a "value" instance,
payload_size
. However, in some of my KSY files, the return type for the getter function for the value is signed while in others it is unsigned. I can't use conditional code to access them, and I'd prefer to avoid a typecast in my source (I'm in C++), so, I would like to specify atype
attribute for the instance, which the the KSY Reference documentation suggests I can do:(Emphasis mine.)
However, the compiler disagrees:
So...which is one wrong, the compiler or the documentation? :-)
(While you're pondering that, is there a way that I can use KS's typecasting to work around the problem? Can I cast the result to a
u2
? If so, what's the syntax for that? Thanks!)The text was updated successfully, but these errors were encountered: