Skip to content

Commit e2c9878

Browse files
hycakirstevengj
authored andcommitted
Add undef to Vector allocations (#29184)
Without the `undef` initializer, the corresponding samples give error for julia version >= 1.0.
1 parent 02aa9bb commit e2c9878

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

doc/src/manual/calling-c-and-fortran-code.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Here is a slightly more complex example that discovers the local machine's hostn
130130

131131
```julia
132132
function gethostname()
133-
hostname = Vector{UInt8}(128)
133+
hostname = Vector{UInt8}(undef, 128)
134134
ccall((:gethostname, "libc"), Int32,
135135
(Ptr{UInt8}, Csize_t),
136136
hostname, sizeof(hostname))
@@ -820,7 +820,7 @@ function sf_bessel_Jn_array(nmin::Integer, nmax::Integer, x::Real)
820820
if nmax < nmin
821821
throw(DomainError())
822822
end
823-
result_array = Vector{Cdouble}(nmax - nmin + 1)
823+
result_array = Vector{Cdouble}(undef, nmax - nmin + 1)
824824
errorcode = ccall(
825825
(:gsl_sf_bessel_Jn_array, :libgsl), # name of C function and library
826826
Cint, # output type
@@ -973,7 +973,7 @@ Other supported conventions are: `stdcall`, `cdecl`, `fastcall`, and `thiscall`
973973
signature for Windows:
974974

975975
```julia
976-
hn = Vector{UInt8}(256)
976+
hn = Vector{UInt8}(undef, 256)
977977
err = ccall(:gethostname, stdcall, Int32, (Ptr{UInt8}, UInt32), hn, length(hn))
978978
```
979979

0 commit comments

Comments
 (0)