SW006013 Microchip Technology, SW006013 Datasheet - Page 46

MPLAB C Compiler For DsPIC DSCs

SW006013

Manufacturer Part Number
SW006013
Description
MPLAB C Compiler For DsPIC DSCs
Manufacturer
Microchip Technology
Series
DsPIC30F/33Fr
Type
MPLAB® C Compilerr
Datasheet

Specifications of SW006013

Supported Families
DsPIC30F, DsPIC33F
Core Architecture
DsPIC
Kit Contents
Software And Docs
Mcu Supported Families
DsPIC30F And DsPIC33F
Tool Function
Compiler
Tool Type
Compiler
Processor Series
dsPIC
Lead Free Status / RoHS Status
na
For Use With/related Products
dSPIC DSCs
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
DS51456E-page 42
offsetof
Description:
Include:
Prototype:
Arguments:
Return Value:
Remarks:
Example:
Gives the offset of a structure member from the beginning of the struc-
ture.
<stddef.h>
#define offsetof(T, mbr)
T
mbr name of member in structure T
Returns the offset in bytes of the specified member (mbr) from the
beginning of the structure.
The macro offsetof is undefined for bitfields. An error message will
occur if bitfields are used.
#include <stddef.h> /* for offsetof */
#include <stdio.h>
struct info {
};
int main(void)
{
}
Output:
Offset of item1 = 0
Offset of item2 = 6
Offset of item3 = 8
Offset of item4 = 10
Explanation:
This program shows the offset in bytes of each structure member from
the start of the structure. Although item1 is only 5 bytes (char
item1[5]), padding is added so the address of item2 falls on an
even boundary. The same occurs with item3; it is 1 byte (char
item3) with 1 byte of padding.
char item1[5];
int item2;
char item3;
float item4;
printf("Offset of item1 = %d\n",
printf("Offset of item2 = %d\n",
printf("Offset of item3 = %d\n",
printf("Offset of item4 = %d\n",
name of structure
offsetof(struct info,item1));
offsetof(struct info,item2));
offsetof(struct info,item3));
offsetof(struct info,item4));
/* for printf */
© 2008 Microchip Technology Inc.

Related parts for SW006013