Skip to content

Commit

Permalink
inline offsetof
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Apr 14, 2024
1 parent 4e66f9d commit 881240d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
15 changes: 0 additions & 15 deletions modules/home-assignments/offsetof.md

This file was deleted.

16 changes: 16 additions & 0 deletions modules/structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ de-reference operator on `foo`.

#solution struct-access-ptr.c

### :wrench: Getting offset of a member

Write a macro (or start with a function with hardcoded values) that will print
the offset of the specified member of a given structure.

```C
offsetof(struct X, a)
```
Hint: exploit the fact that pointer can be assigned an integer (0) + use pointer
arithmetics
Note: `offsetof()` is a standard macro available since ANSI C via `stddef.h`.
#solution offsetof.c
## Structure initialization
Can initialize a structure in its definition using the initiator list of values.
Expand Down

0 comments on commit 881240d

Please sign in to comment.