C/C++ and Fortran

 View Only

Using the _LARGE_FILES macro to access large files with C++ programs on AIX

By Jake Egan posted Tue February 27, 2024 10:11 AM



Large files on AIX are files larger than 2 gigabytes (2 GB). The _LARGE_FILES macro enables programs to handle large files. When the macro is defined, all data types, structures, and subroutine names are mapped to their 64-bit versions.

The macro can be defined on the command-line.

$ ibm-clang++_r -D_LARGE_FILES a.cpp

It can also be defined in the program before including the headers for the desired subroutines.

#define _LARGE_FILES
#include <fcntl.h>

For example, consider the following call to the open function.

int file = open("example.txt", O_RDONLY); // Before preprocessing

Either method of defining the macro results in the 64-bit version of open (open64) being used after preprocessing.

int file = open64("example.txt", 0); // After preprocessing

Side effects of using _LARGE_FILES with C++ system include files

When the _LARGE_FILES macro was added to the C system include files it was not intended for use with the C++ system include files. The macro defines other macros that alter C library function calls so that, after preprocessing, the functions refer to their counterparts for handling large files. The preprocessor does not use contextual information so it may inadvertently change other uses of the same identifier, even within C++ qualified identifiers, with unintended results. Such changes may potentially cause issues when linking. If you encounter problems using the _LARGE_FILES macro, there is an alternative way to access large files.

Alternative to using the _LARGE_FILES macro

Programs can be rewritten to explicitly call the 64-bit versions of subroutines, rather than using the macro. This may take more effort than simply defining the macro, but it ensures that only the intended subroutines are affected.

In the following example, open64 is explicitly called instead of defining _LARGE_FILES.

int file = open64(“example.txt", O_RDONLY); // Before preprocessing

More information on large files can be found here: AIX documentation on large files.