Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/o/offsetof.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/o/offsetof.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/o/offsetof.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/o/offsetof.html on line 8

offsetof()

Return the offset of an element within a structure

Synopsis:

#include <stddef.h>

#define offsetof( composite, name ) …

Arguments:

composite
A struct or union.
name
The name of an element in composite.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The offsetof() macro returns the offset of the element name within the struct or union composite.

This provides a portable method to determine the offset.

Returns:

The offset of name.

Examples:

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

struct new_def
{
    char *first;
    char second[10];
    int third;
};

int main( void )
{
    printf( "first:%d second:%d third:%d\n",
            offsetof( struct new_def, first ),
            offsetof( struct new_def, second ),
            offsetof( struct new_def, third ) );
            
    return EXIT_SUCCESS;
}

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

Caveats:

This is a macro.


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/o/offsetof.html on line 140

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/o/offsetof.html on line 140