_GNU_SOURCE and __USE_GNU

_GNU_SOURCE is the only one you should ever define yourself. __USE_GNU is defined internally through a mechanism in features.h (which is included by all other glibc headers) when _GNU_SOURCE is defined, and possibly under other conditions. Defining or undefining __USE_GNU yourself will badly break the glibc headers.

How can you compare two character strings statically at compile time

Starting with C++17 std::string_view is available. It supports constexpr comparisson: #include <string_view> constexpr bool strings_equal(char const * a, char const * b) { return std::string_view(a)==b; } int main() { static_assert(strings_equal(“abc”, “abc” ), “strings are equal”); static_assert(!strings_equal(“abc”, “abcd”), “strings are not equal”); return 0; } Demo

run a program with more than one source files in GNU c++ compiler

The technical term for ‘multiple files’ would be translation units: g++ file1.cpp file2.cpp -o program Or you separate compilation and linking g++ -c file1.cpp -o file1.o g++ -c file2.cpp -o file2.o # linking g++ file1.o file2.o -o program But that usually doesn’t make sense unless you have a larger project (e.g. with make) and want … Read more

Include binary file with GNU ld linker script

You could try using objcopy to convert it to a normal object you can link in, and then reference its symbols in the linker script like you would do to a normal object. From the objcopy manual page: -B bfdarch –binary-architecture=bfdarch Useful when transforming a raw binary input file into an object file. In this … Read more

Is there a symbol that represents the current address in GNU GAS assembly?

Excerpt from info as (GNU Binutils 2.21.90), or online in the GAS manual: https://sourceware.org/binutils/docs/as/Dot.html 5.4 The Special Dot Symbol The special symbol . refers to the current address that as is assembling into. Thus, the expression melvin: .long . defines melvin to contain its own address. Assigning a value to . is treated the same … Read more

__attribute__((const)) vs __attribute__((pure)) in GNU C

From the documentation for the ARM compiler (which is based on gcc): __attribute__((pure)) function attribute Many functions have no effects except to return a value, and their return value depends only on the parameters and global variables. Functions of this kind can be subject to data flow analysis and might be eliminated. __attribute__((const)) function attribute … Read more

Seeking and reading large files in a Linux C++ application

fseek64 is a C function. To make it available you’ll have to define _FILE_OFFSET_BITS=64 before including the system headers That will more or less define fseek to be actually fseek64. Or do it in the compiler arguments e.g. gcc -D_FILE_OFFSET_BITS=64 …. http://www.suse.de/~aj/linux_lfs.html has a great overviw of large file support on linux: Compile your programs … Read more