offsetof(3)


NAME

   offsetof - offset of a structure member

SYNOPSIS

   #include <stddef.h>

   size_t offsetof(type, member);

DESCRIPTION

   The  macro  offsetof()  returns the offset of the field member from the
   start of the structure type.

   This macro is useful because the sizes of the  fields  that  compose  a
   structure  can  vary  across  implementations, and compilers may insert
   different numbers of padding bytes between  fields.   Consequently,  an
   element's  offset  is  not necessarily given by the sum of the sizes of
   the previous elements.

   A compiler error will result  if  member  is  not  aligned  to  a  byte
   boundary (i.e., it is a bit field).

RETURN VALUE

   offsetof()  returns  the  offset  of  the given member within the given
   type, in units of bytes.

CONFORMING TO

   POSIX.1-2001, POSIX.1-2008, C89, C99.

EXAMPLE

   On a Linux/i386 system, when compiled using the default gcc(1) options,
   the program below produces the following output:

       $ ./a.out
       offsets: i=0; c=4; d=8 a=16
       sizeof(struct s)=16

   Program source

   #include <stddef.h>
   #include <stdio.h>
   #include <stdlib.h>

   int
   main(void)
   {
       struct s {
           int i;
           char c;
           double d;
           char a[];
       };

       /* Output is compiler dependent */

       printf("offsets: i=%zd; c=%zd; d=%zd a=%zd\n",
               offsetof(struct s, i), offsetof(struct s, c),
               offsetof(struct s, d), offsetof(struct s, a));
       printf("sizeof(struct s)=%zd\n", sizeof(struct s));

       exit(EXIT_SUCCESS);
   }

COLOPHON

   This  page  is  part of release 4.09 of the Linux man-pages project.  A
   description of the project, information about reporting bugs,  and  the
   latest     version     of     this    page,    can    be    found    at
   https://www.kernel.org/doc/man-pages/.


More Linux Commands

manpages/ccoshl.3.html
ccoshl(3) - complex hyperbolic cosine - Linux manual page...
The complex hyperbolic cosine function is defined as: ccosh(z) = (exp(z)+exp(-z))/2 VERSIONS These functions first appeared in glibc in version 2.1. CONFORMING

manpages/unstr.1.html
unstr(1) create a random access file for storing strings br
strfile reads a file containing groups of lines separated by a line containing a single percent % sign (or other specified delimiter character) and creates a da

manpages/Tcl_ChannelSetOptionProc.3.html
Tcl_ChannelSetOptionProc(3) - procedures for creating and ma
Tcl uses a two-layered channel architecture. It provides a generic upper layer to enable C and Tcl programs to perform input and output using the same APIs for

manpages/wait.2.html
wait(2) - wait for process to change state - Linux man page
All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed.

manpages/SDL_JoystickGetButton.3.html
SDL_JoystickGetButton(3) - Get the current state of a given
SDL_JoystickGetButton returns the current state of the given button on the given joystick. RETURN VALUE 1 if the button is pressed. Otherwise, 0. SEE ALSO SDL_J

manpages/rpmdeps.8.html
rpmdeps(8) - Generate RPM Package Dependencies (Man Page)...
rpmdeps generates package dependencies for the set of FILE arguments. Each FILE argument is searched for Elf32/Elf64, script interpreter, or per-script dependen

manpages/XML::PatAct::MatchName.3pm.html
XML::PatAct::MatchName(3pm) - A pattern module for matching
XML::PatAct::MatchName is a pattern module for use with PatAct drivers for applying pattern-action lists to XML parses or trees. XML::PatAct::MatchName is a sim

manpages/regtree.1.html
regtree(1) Textmode registry viewer - Linux manual page.....
The regtree utility prints out all the contents of a Windows registry file. Subkeys are printed with one level more indentation than their parents. OPTIONS --he

manpages/XListPixmapFormats.3.html
XListPixmapFormats(3) - image format functions and macros...
The XListPixmapFormats function returns an array of XPixmapFormatValues structures that describe the types of Z format images supported by the specified display

manpages/isprint_l.3.html
isprint_l(3) character classification functions (Man Page)
These functions check whether c, which must have the value of an unsigned char or EOF, falls into a certain character class according to the specified locale. T

manpages/logger.1.html
logger(1) - a shell command interface to the syslog(3) syste
logger makes entries in the system log. It provides a shell command interface to the syslog(3) system log module. OPTIONS -d, --udp Use datagram (UDP) only. By

manpages/Encode::JP.3pm.html
Encode::JP(3pm) - Japanese Encodings - Linux manual page....
To find out how to use this module in detail, see Encode. Note on ISO-2022-JP(-1)? ISO-2022-JP-1 ( RFC2237 ) is a superset of ISO-2022-JP ( RFC1468 ) which adds





We can't live, work or learn in freedom unless the software we use is free.