Skip to content

Commit 65c6bda

Browse files
authored
add an example of using sizeof on a struct with padding (#47342)
1 parent b0c2ad9 commit 65c6bda

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

base/essentials.jl

+11
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,17 @@ julia> sizeof(1.0)
539539
540540
julia> sizeof(collect(1.0:10.0))
541541
80
542+
543+
julia> struct StructWithPadding
544+
x::Int64
545+
flag::Bool
546+
end
547+
548+
julia> sizeof(StructWithPadding) # not the sum of `sizeof` of fields due to padding
549+
16
550+
551+
julia> sizeof(Int64) + sizeof(Bool) # different from above
552+
9
542553
```
543554
544555
If `DataType` `T` does not have a specific size, an error is thrown.

0 commit comments

Comments
 (0)