Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
stddef.h File Reference

Standard C Libraries -. More...

Go to the source code of this file.

Macros

#define NULL   (0)
 
#define offsetof(T, mbr)   ((int)&(((T *)0)->mbr))
 

Typedefs

typedef __PTRDIFF_TYPE__ ptrdiff_t
 
typedef __SIZE_TYPE__ size_t
 
typedef __WCHAR_TYPE__ wchar_t
 

Detailed Description

Standard C Libraries -.

Compiler:
MPLAB XC16 compiler

Description

The header file, stddef.h, consists of several types and macros that are of general use in programs.

Software License Agreement

The documentation in this header file has been copied from the documentation provided with the Microchip MPLAB XC16 compiler. The original license agreement included with the XC16 compiler applies!

Macro Definition Documentation

#define NULL   (0)

Description: The value of a null pointer constant.

Include: <stddef.h>

Examples:
usb/device_MIDI/main.c, and usb/device_MIDI_LCD/main.c.
#define offsetof (   T,
  mbr 
)    ((int)&(((T *)0)->mbr))

Description: Gives the offset of a structure member from the beginning of the structure.

Include: <stddef.h>

Parameters
Tname of structure
mbrname of member in structure T
Returns
Returns the offset in bytes of the specified member (mbr) from the beginning of the structure.

Remarks:
The macro offsetof is undefined for bitfields. An error message will occur if bitfields are used.

Example:

#include <stddef.h> // for offsetof
#include <stdio.h> // for printf
struct info {
char item1[5];
int item2;
char item3;
float item4;
};
int main(void) {
printf("Offset of item1 = %d\n",
offsetof(struct info, item1));
printf("Offset of item2 = %d\n",
offsetof(struct info, item2));
printf("Offset of item3 = %d\n",
offsetof(struct info, item3));
printf("Offset of item4 = %d\n",
offsetof(struct info, item4));
}

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.

Typedef Documentation

typedef __PTRDIFF_TYPE__ ptrdiff_t

Description: The type of the result of subtracting two pointers.

Include: <stddef.h>

typedef __SIZE_TYPE__ size_t

Description: The type of the result of the sizeof operator.

Include: <stddef.h>

typedef __WCHAR_TYPE__ wchar_t

Description: A type that holds a wide character value.

Include: <stddef.h>