Skip to content

Commit

Permalink
Merge pull request JuliaLang#9483 from JuliaLang/nalimilan/ptr
Browse files Browse the repository at this point in the history
Add <(::Ptr, ::Ptr)
  • Loading branch information
JeffBezanson committed Dec 30, 2014
2 parents 8b855cc + 5196915 commit b18252a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ eltype{T}(::Ptr{T}) = T
## limited pointer arithmetic & comparison ##

==(x::Ptr, y::Ptr) = uint(x) == uint(y)
isless(x::Ptr, y::Ptr) = isless(uint(x), uint(y))
-(x::Ptr, y::Ptr) = uint(x) - uint(y)

+(x::Ptr, y::Integer) = oftype(x, (uint(x) + (y % UInt) % UInt))
Expand Down
18 changes: 18 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,24 @@ begin
@test typeof(b) === SI{1,-2,1}
end

# pointer arithmetic
begin
local a,b,c
a = C_NULL
b = C_NULL + 1
c = C_NULL - 1

@test a != b != c
@test UInt(a) == 0
@test UInt(b) == 1
@test UInt(c) == typemax(UInt)

@test b - a == -(a - b) == 1
@test c - a == -(a - c) == typemax(UInt)
@test c - b == -(b - c) == typemax(UInt) - 1
@test a < b < c
end

# pull request 1270
begin
local a,p, a2,p2
Expand Down

0 comments on commit b18252a

Please sign in to comment.