-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Denis Pronin <Pronin.D@raidix.com>
- Loading branch information
Showing
3 changed files
with
36 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef _CONTAINER_OF_H | ||
#define _CONTAINER_OF_H | ||
|
||
#ifdef __cplusplus | ||
|
||
#include <cstdlib> | ||
#include <cstddef> | ||
|
||
extern "C" { | ||
|
||
#define container_of(ptr, type, member) ({ \ | ||
auto const *__mptr = static_cast<__typeof__( ((type *)0)->member ) const*>(ptr); \ | ||
(type *)( (char *)__mptr - offsetof(type,member) );}) | ||
} | ||
|
||
#else // __cplusplus | ||
|
||
#include <stdlib.h> | ||
#include <stddef.h> | ||
|
||
#define container_of(ptr, type, member) ({ \ | ||
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ | ||
(type *)( (char *)__mptr - offsetof(type,member) );}) | ||
#endif | ||
|
||
#endif // _CONTAINER_OF_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters