.\" -*- coding: UTF-8 -*- .\" Copyright (C) 2006 Justin Pryzby .\" and Copyright (C) 2006 Michael Kerrisk .\" .\" %%%LICENSE_START(PERMISSIVE_MISC) .\" Permission is hereby granted, free of charge, to any person obtaining .\" a copy of this software and associated documentation files (the .\" "Software"), to deal in the Software without restriction, including .\" without limitation the rights to use, copy, modify, merge, publish, .\" distribute, sublicense, and/or sell copies of the Software, and to .\" permit persons to whom the Software is furnished to do so, subject to .\" the following conditions: .\" .\" The above copyright notice and this permission notice shall be .\" included in all copies or substantial portions of the Software. .\" .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, .\" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. .\" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY .\" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, .\" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE .\" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .\" %%%LICENSE_END .\" .\" References: .\" /usr/lib/gcc/i486-linux-gnu/4.1.1/include/stddef.h .\" glibc-doc .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH OFFSETOF 3 "1 novembre 2020" GNU "Manuel du programmeur Linux" .SH NOM offsetof \- Décalage d'un membre d'une structure .SH SYNOPSIS .nf \fB#include \fP .PP \fBsize_t offsetof(\fP\fItype\fP\fB, \fP\fImembre\fP\fB);\fP .fi .SH DESCRIPTION La macro \fBoffsetof\fP() renvoie le décalage du champ \fImembre\fP à partir du début de la structure \fItype\fP. .PP Cette macro est utile car la taille des champs qui composent une structure peut varier d'une implémentation à l'autre. De plus, les compilateurs peuvent insèrer des octets entre les champs pour des questions d'alignement, le nombre de ces octets dépendant de chaque compilateur. Ainsi, le décalage d'un élément n'est pas forcément égal à la somme des tailles des membres qui le précèdent. .PP Une erreur de compilateur sera signalée si \fImembre\fP n'est pas aligné avec une frontière d'octet (c'est\-à\-dire qu'il s'agit d'un champ de bits). .SH "VALEUR RENVOYÉE" \fBoffsetof\fP() renvoie le décalage (en octets) du \fImembre\fP spécifié à l'intérieur de la structure \fItype\fP. .SH CONFORMITÉ POSIX.1\-2001, POSIX.1\-2008, C89, C99. .SH EXEMPLES Sur un système Linux/i386, le programme ci\-dessous, compilé avec les options par défaut de \fBgcc\fP(1), affichera le résultat suivant\ : .PP .in +4n .EX $\fB ./a.out\fP décalages: i=0 c=4 d=8 a=16 sizeof(struct s)=16 .EE .in .SS "Source du programme" \& .EX #include #include #include int main(void) { struct s { int i; char c; double d; char a[]; }; /* La sortie dépend du compilateur */ printf("décalages : i=%zu; c=%zu; d=%zu a=%zu\en", offsetof(struct s, i), offsetof(struct s, c), offsetof(struct s, d), offsetof(struct s, a)); printf("sizeof(struct s)=%zu\en", sizeof(struct s)); exit(EXIT_SUCCESS); } .EE .SH COLOPHON Cette page fait partie de la publication\ 5.10 du projet \fIman\-pages\fP Linux. Une description du projet et des instructions pour signaler des anomalies et la dernière version de cette page peuvent être trouvées à l'adresse \%https://www.kernel.org/doc/man\-pages/. .PP .SH TRADUCTION La traduction française de cette page de manuel a été créée par Christophe Blaess , Stéphan Rafin , Thierry Vignaud , François Micaux, Alain Portal , Jean-Philippe Guérard , Jean-Luc Coulon (f5ibh) , Julien Cristau , Thomas Huriaux , Nicolas François , Florentin Duneau , Simon Paillard , Denis Barbier et David Prévot . .PP Cette traduction est une documentation libre ; veuillez vous reporter à la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 .UE concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE. .PP Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à .MT debian-l10n-french@lists.debian.org .ME .