You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/11/06 16:03:23 UTC

[GitHub] andrzej-kaczmarek opened a new pull request #1508: kernel/os: Add helper CONTAINER_OF macro

andrzej-kaczmarek opened a new pull request #1508: kernel/os: Add helper CONTAINER_OF macro
URL: https://github.com/apache/mynewt-core/pull/1508
 
 
   This is a convenience macro to calculate original pointer of "parent"
   object using a pointer to one of its members. It's commonly used in
   e.g. Linux kernel and Zephyr Project so it should be also useful in
   Mynewt :)
   
   For example, with following structure:
   ```
   struct foo {
       int a;
       struct bar bar;
       int c;
   }
   ```
   Let's assume we have:
   ```
   struct foo g_foo;
   struct bar *x = &g_foo.bar;
   ```
   And we can use `CONTAINER_OF` to calculate pointer to `g_foo` using `x`:
   ```
   struct foo *foo = CONTAINER_OF(x, struct foo, bar);
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services