Implicit Method to Enforce Endianess

The implicit method to enforce endianess is designed to minimize changes at the application source code level. This method lets you set the appropriate byte order for a whole file or for an entire application through command line options and the use of prolog and epilog files.

To enforce endianess for an entire application, use the -big-endian or -little-endian command line option. These options set the compiler's default endian convention to the big or little endian convention, respectively.

You can also enforce endianess for a particular source file or an entire directory through the mechanism of prolog and epilog files. For each include file (for example,#include <file.h> or#include "file.h" directive), the compiler checks if prolog and epilog files are associated with the file.h. If this association exists, a prolog file is processed right before the file.h and an epilog file is processed right after the file.h:

#include "prologfile.h"
#include "file.h"
#include "epilogfile.h"

For more information on how to associate a source file with prolog\epilog files, see the description of the -pe-udir-rule and -pe-idir-rule options.

The compiler makes associations differently for files searched in user and in system include paths.

  • For files found through user include paths, the compiler first checks associations from -pe-udir-rule settings, and then from -pe-idir-rule settings.
  • For files found through system include paths, the compiler first checks associations from -pe-idir-rule settings, otherwise it uses default __intel_prolog.h and __intel_epilog.h located at the compiler include directory.

    Note

    It is possible to change defaults by overriding __intel_prolog.h and __intel_epilog.h files using the -pe-idir-rule option (for example, -pe-idir-rule=".* my_prolog.h my_epilog.h") or by making necessary changes in default prolog/epilog files directly. When compiler checks associations in the -pe-udir-rule or -pe-idir-rule settings, the first matching association is used.

To better understand how prolog and epilog files are searched by the compiler, consider the following diagram:



Examples of prolog and epilog Files

prolog files for big endian directories with a desired C name prefix of __be_

#pragma byte_order (push, bigendian)
#pragma extern_prefix (push, "__be_")

prolog files for little endian directories with no C name prefix

#pragma byte_order (push, littleendian)
#pragma extern_prefix (push, "")

epilog file to pop endian and C name prefix for any directory

#pragma byte_order pop
#pragma extern_prefix pop

You can pair the example epilog file with either prolog file.

Examples of Command Line Entries

You can also select the desired endian mode and specify a C name prefix on the command line. Some examples of the command lines are shown below.

To compile foo.c as little endian using compiler-provided prolog and epilog files, use the following command:

icc -c -little-endian foo.c

Headers from the system include directories will be wrapped in __intel_prolog.h/ __intel_epilog.h files from the compiler include directory.

To compile foo.c as big endian using compiler-provided prolog/epilog files prefixing C names with __be_, use the following command:

icc -c -big-endian -extern-prefix="__be_" foo.c

Any pragmas in prolog or epilog files or in user source code override the settings on the command line.

See Also

For more complete information about compiler optimizations, see our Optimization Notice.