# Why is seek zero-based?

**URL:** <https://discourse.julialang.org/t/why-is-seek-zero-based/55569>\
**Category:** General Usage\
**Created:** [February 18, 2021, 7:01pm UTC](https://discourse.julialang.org/t/why-is-seek-zero-based/55569 "2021-02-18T19:01:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjia](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@Benjia](https://discourse.julialang.org/u/Benjia)\
**Post date:** [February 18, 2021, 7:01pm UTC](https://discourse.julialang.org/t/why-is-seek-zero-based/55569/1 "2021-02-18T19:01:18Z")

</div>

To go to the start of an `IOStream`, you have to do `seek(io, 0)`. Why is this? I just spent about 30 minutes trying to debug an error caused by using `seek(io, 1)` instead.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 18, 2021, 7:34pm UTC](https://discourse.julialang.org/t/why-is-seek-zero-based/55569/2 "2021-02-18T19:34:44Z")

</div>

It’s just the standard convention for file positions across virtually all languages: refer to an _offset_ relative to the start of the file (and hence be zero-based).

This convention is used even in languages like [Matlab (`fseek`)](https://www.mathworks.com/help/matlab/ref/fseek.html), [Fortran (`fseek`)](https://software.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/language-reference/a-to-z-reference/e-to-f/fseek.html), [R (`seek`)](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/seek), and [Lua (`file::seek`)](https://www.tutorialspoint.com/lua/lua_file_io.htm) that are otherwise 1-based by default, so it would be weird for Julia to differ.

---

<div class="post-metadata">

**Author:** ![Benjia](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@Benjia](https://discourse.julialang.org/u/Benjia)\
**Post date:** [February 18, 2021, 11:46pm UTC](https://discourse.julialang.org/t/why-is-seek-zero-based/55569/3 "2021-02-18T23:46:51Z")

</div>

Thanks Steven, that seems reasonable.

Perhaps a mention of this would be handy in the docs for `seek`.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [February 18, 2021, 11:59pm UTC](https://discourse.julialang.org/t/why-is-seek-zero-based/55569/4 "2021-02-18T23:59:20Z")

</div>

> [@Benjia](#):
>
> Perhaps a mention of this would be handy in the docs for `seek` .

Sure, you can do it yourself by opening a pull request for Julia! 🙂

Note also that to go to the beginning of the stream you can use [`seekstart`](https://docs.julialang.org/en/v1/base/io-network/#Base.seekstart).
