-
Notifications
You must be signed in to change notification settings - Fork 8
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
Improve C99 Compatibility #4
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4 +/- ##
===========================================
- Coverage 68.49% 57.14% -11.36%
===========================================
Files 1 2 +1
Lines 73 91 +18
===========================================
+ Hits 50 52 +2
- Misses 23 39 +16
Continue to review full report at Codecov.
|
Nice! This also makes it possible to use the slightly nicer syntax from @cenum Foo::Cint begin
foo
bar
end This looks like a bug though: julia> @cenum Foo begin
foo
bar
end
julia> typeof(foo)
Cenum Foo:
foo = 0
foo = 0 vs julia> @enum Foo begin
foo
bar
end
julia> typeof(foo)
Enum Foo:
foo = 0
bar = 1
But bitwise operators still just yield the underlying type (#3), I guess that's intended? |
yes. now this package only defines generic bitwise operators for Cenum-Cenum, Cenum-Integer, and Integer-Cenum inputs. In the example below, it's hard to determine which Cenum type should be chosen as the return type. I think it's ok to just leave this problem to end-users since it's easy to overload these operators and define different promote rules for their own purpose.
This behavior is the same as the one in C/C++: C++ > typedef enum {
xxx,
yyy,
} Foo;
C++ > xxx
Cxx.CxxCore.CppEnum{:Foo,UInt32}(0x00000000)
C++ > xxx | yyy
1 |
This is fixed now: julia> @cenum(Fruit, apple=1, orange=2, kiwi=2)
julia> typeof(apple)
Cenum Fruit:
apple = 1
orange = 2
kiwi = 2 But as one value could have more than one names in C's enum, it's hard for julia> kiwi
orange::Fruit = 2
julia> kiwi === orange
true |
This is just a copy of the enum.jl from Julia Base, with minimal tweaks to be in compliance with the C99 standard:
I don't find anywhere in the standard that specifies the behavior when casting a non-member Integer to Enum, so it is now allowed and the
show
method will mark it asUnkownMember
.As for those bitwise operators,
UInt32
is no longer being treated specially, the return type is promoted. However, it's still anInteger
since this is the default behavior of many C/C++ compilers.One needs to either overload the operator or explicitly cast the return value to the target enum type.
cc @maleadt @SimonDanisch