COHERENT manpages
This page displays the COHERENT manpage for #pragma [Perform implementation-specific preprocessing].
List of available manpages
Index
#pragma -- Preprocessing Directive
Perform implementation-specific preprocessing
#pragma is the C preprocessing directive that triggers implementation-
specific behavior. The ANSI Standard demands that every conforming
implementation of C document what #pragma does.
COHERENT recognizes one use of #pragma:
#pragma align [n]
This directive permits COHERENT to conform to the Intel Binary
Compatability Standard (BCS), which specifies alignment requirements for
structs.
The BCS requires that a struct be aligned consistently with the alignment
of its most strictly aligned member. For example, the structure
struct s {
short s_s1;
int s_i;
short s_s2;
};
must put member s_i at offset 4, not 2 (because int is dword-aligned). If
you have an array of struct s objects, the second will be at offset 12, not
10 (or 8), because struct s itself must also be dword-aligned.
This, unfortunately, creates problems with existing compiled code, and with
some standards, e.g., COFF. For example, a struct filsys (a COHERENT file
system, e.g., on a floppy or hard disk) is defined in <sys/filsys.h>
as starting out just like the above:
struct filsys {
unsigned short s_isize;
daddr_t s_fsize;
short s_nfree;
...
};
Because daddr_t is long, COHERENT would compile this and expect to find
s_fsize at offset 4 (not 2) and s_nfree at offset 8 (not 6); but this is
not where the bits actually fall on an existing file system. So we
circumvent the BCS with #pragma align. The directive #pragma align n means
``align objects on n-byte boundaries, at most,'' and #pragma align means
``restore default alignment.'' Thus, <sys/filsys.h> is edited to
read:
struct filsys {
unsigned short s_isize;
#pragma align 2
daddr_t s_fsize;
#pragma align
short s_nfree;
...
};
and the compiler thinks the struct members fall at offsets 0, 2 and 6,
which preserves compatibility with existing binary objects.
See Also
cpp,
C preprocessor
ANSI Standard, §6.8.6







