Skip to content

Commit

Permalink
Anar
Browse files Browse the repository at this point in the history
  • Loading branch information
snarlferb committed Aug 5, 2024
1 parent 7c86a16 commit 3dd39f1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions vac.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,21 @@
It sounds more complicated than it is, since its describing multiple scenarios, however you can
take it from the last scenario, and sortve trace the steps backwards so to speak...

The last scenario, we said we could take that `(*database>pack)` to access the `buffer` member of the `Anar` struct.
The last scenario, we said we could take that `(*database->pack)` to access the `buffer` member of the `Anar` struct.

In C, when you mix (.) period and (->) arrow operators with dereferencing, parentheses adheres the order of
operations. Without parentheses, you can’t directly use the (.) operator on a pointer without first dereferencing it.

For example, consider *database->pack.nar.buffer Here’s how the C compiler interprets it:

`database->pack` is a pointer to Vac.
`database->pack.nar` is an invalid syntax because (->) should be used for accessing members from a pointer
to a struct, and `nar` is not a member of ` Vac * ` but of `Vac`
`database->pack.nar` is an invalid syntax.

To correctly access buffer, you need to dereference `database->pack` to get the `Vac` struct.
Access the `nar` member of the `Vac` struct. And access the `buffer` member of the `Anar` struct (as we said when describing the last scenario)
First, (->) is used for accessing members from a pointer to a struct. And we want to use `nar`, however is not a member
of ` Vac * `. It is a member of `Vac`.

We have to correctly access `buffer` of the `Anar` struct, and `nar` from the rest, you need to dereference
`database->pack` to get the `Vac` struct. Once you understand that, it should make sense.

So the correct syntax in that particular situation would be:
<span class="alt-text">
Expand All @@ -71,5 +73,4 @@
<span class="alt-text">
Vac *exac = *database-&gt;pack;</span>

Which would allow you to use it as `exac-&gt;nar.buffer`

Which would allow you to use it as `exac-&gt;nar.buffer`, and is just one example of something you might do.

0 comments on commit 3dd39f1

Please sign in to comment.