Mercurial > gnulib
annotate lib/flexmember.h @ 40196:e63f5d3edab5
relocatable-prog: Update documentation.
* doc/relocatable-maint.texi (Supporting Relocation): Update to match
the recent changes.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 24 Feb 2019 01:49:15 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
1 /* Sizes of structs with flexible array members. |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
2 |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
3 Copyright 2016-2019 Free Software Foundation, Inc. |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
4 |
19084
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
5 This file is part of the GNU C Library. |
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
6 |
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
7 The GNU C Library is free software; you can redistribute it and/or |
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
8 modify it under the terms of the GNU Lesser General Public |
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
9 License as published by the Free Software Foundation; either |
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
10 version 2.1 of the License, or (at your option) any later version. |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
11 |
19084
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
12 The GNU C Library is distributed in the hope that it will be useful, |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
19084
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
15 Lesser General Public License for more details. |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
16 |
19084
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
17 You should have received a copy of the GNU Lesser General Public |
57cf6c9186eb
glob: merge from glibc with Zanella glob changes
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
18 License along with the GNU C Library; if not, see |
19190 | 19 <https://www.gnu.org/licenses/>. |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
20 |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
21 Written by Paul Eggert. */ |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
22 |
18405
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
23 #include <stddef.h> |
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
24 |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
25 /* Nonzero multiple of alignment of TYPE, suitable for FLEXSIZEOF below. |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
26 On older platforms without _Alignof, use a pessimistic bound that is |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
27 safe in practice even if FLEXIBLE_ARRAY_MEMBER is 1. |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
28 On newer platforms, use _Alignof to get a tighter bound. */ |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
29 |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
30 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 |
18405
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
31 # define FLEXALIGNOF(type) (sizeof (type) & ~ (sizeof (type) - 1)) |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
32 #else |
18405
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
33 # define FLEXALIGNOF(type) _Alignof (type) |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
34 #endif |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
35 |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
36 /* Upper bound on the size of a struct of type TYPE with a flexible |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
37 array member named MEMBER that is followed by N bytes of other data. |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
38 This is not simply sizeof (TYPE) + N, since it may require |
18405
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
39 alignment on unusually picky C11 platforms, and |
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
40 FLEXIBLE_ARRAY_MEMBER may be 1 on pre-C11 platforms. |
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
41 Yield a value less than N if and only if arithmetic overflow occurs. */ |
18403
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
42 |
4434607ac1ce
flexmember: port better to GCC + valgrind
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff
changeset
|
43 #define FLEXSIZEOF(type, member, n) \ |
18405
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
44 ((offsetof (type, member) + FLEXALIGNOF (type) - 1 + (n)) \ |
c202f10ffda5
flexmember: new macro FLEXALIGNOF
Paul Eggert <eggert@cs.ucla.edu>
parents:
18403
diff
changeset
|
45 & ~ (FLEXALIGNOF (type) - 1)) |