From: arighi Date: Wed, 17 Mar 2010 11:53:11 +0000 (+0000) Subject: Add alignof() macro. X-Git-Tag: 2.4.0~40 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=07e34b5dabbe1609ff848b2137ccbbff33619144;p=bertos.git 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 --- 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.