From 07e34b5dabbe1609ff848b2137ccbbff33619144 Mon Sep 17 00:00:00 2001 From: arighi Date: Wed, 17 Mar 2010 11:53:11 +0000 Subject: [PATCH] Add alignof() macro. This macro returns the alignment in memory of a generic data type. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3224 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cfg/compiler.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bertos/cfg/compiler.h b/bertos/cfg/compiler.h index 87cdd942..5cacf1dc 100644 --- a/bertos/cfg/compiler.h +++ b/bertos/cfg/compiler.h @@ -490,6 +490,16 @@ typedef unsigned char page_t; /**< Type for banked memory pages. */ */ #define countof(a) (sizeof(a) / sizeof(*(a))) #endif +#ifndef alignof + /** + * Return the alignment in memory of a generic data type. + * + * \note We need to worry about alignment when allocating memory that + * will be used later by unknown objects (e.g., malloc()) or, more + * generally, whenever creating generic container types. + */ + #define alignof(type) offsetof(struct { char c; type member; }, member) +#endif /** * Cast a member of a structure out to the containing structure. -- 2.25.1