26 questions from the last 30 days
Advice
0
votes
4
replies
184
views
Why does GCC transform a >= 4 into a > 3 at -O0? JG seems to be more complex than JGE
Title: Why does GCC transform a >= 4 into a > 3 at -O0? JG seems more complex than JGE
I'm analyzing a simple C code on godbolt and found GCC's code generation puzzling:
long a;
a = a >= 4;
...
Best practices
2
votes
10
replies
288
views
How to tell the C compiler that data pointed to by a pointer won't be constantly modified by another thread after being passed to a function?
In C, when I pass a pointer to a function, the compiler always seems to assume that the data pointed to by that pointer might be continuously modified in another thread, even though in actual API ...
11
votes
1
answer
619
views
constexpr self-referencing struct
Consider the following simplified code:
template <class T> class Foo {
T t;
const T* t_ptr;
public:
constexpr Foo(T t): t(t), t_ptr(&this->t) {}
constexpr Foo(const Foo&...
1
vote
2
answers
149
views
Different handling of signed value between MSVC and GCC
Take the below piece of code, that simply Trims a string, removing whitespace characters from either end:
const std::string TrimString(const std::string& s)
{
const auto iter = std::find_if(s....
3
votes
2
answers
105
views
Handling Buffer Size Errors in strftime: ERANGE vs EOVERFLOW
I have an application where I need to generate date and time based on the locale using the strftime function provided by C's time.h:
#include <stdio.h>
#include <time.h>
#include <...
Advice
0
votes
8
replies
144
views
Is it possible to package binary data inside the binary without having it in memory?
I recently learned about C23's implementation for #embed, so I was wondering if I can use that with extern in a c++23 program/game to have all 3d models and assets baked into the exe but not in memory ...
3
votes
2
answers
190
views
Why do GCC and Clang fail to auto-vectorize simple loop?
I have two functions counting the occurrences of a target char in the given input buffer. The functions vary only in how they communicate the result back to the caller; one returns the result and the ...
Tooling
0
votes
3
replies
98
views
Which IDE and tools for gcc C development?
Which IDE and tools are best suited for gcc C development? I currently use vscode and the tried using the ms-vscode.cpptools extension which "supports" gcc C. But extensions like nested ...
3
votes
1
answer
119
views
std::filesystem::path::parent_path() GCC vs Clang behavior with multiple leading separators
I stumbled upon different behavior of std::filesystem::path::parent_path() when a path contains leading slashes. Clang says that the parent of ///a is /// (which is what I would expect), but GCC says ...
Advice
2
votes
6
replies
121
views
determine cpu after c++ compilation with gcc?
Does anyone know if there is, in c++, any way to determine at runtime the cpu characteristics of the machine that compiled the code? For example, in gcc (which I'm using) the preprocessor variable ...
6
votes
0
answers
143
views
Optimized Assembly Generation for Unsigned Multiplication Leads to Unexpected Result for Cortex-M0+
I was experimenting with some fixed-point arithmetic on the Cortex-M0+ in Godbolt's compiler explorer and came across an interesting behaviour with respect to the optimisation of a multiplication ...
4
votes
1
answer
95
views
Why is attribute noinline ignored by gcc-15.1.0 in this example?
Looking at this benchmark about a custom std::function implementation: https://github.com/PacktPublishing/Hands-On-Design-Patterns-with-CPP-Second-Edition/blob/main/Chapter06/09_function.C
I tried to ...
Advice
0
votes
6
replies
80
views
object file is twice larger than expected
I have a AVR GCC toolchain compiled to work on aarch64-linux-gnu devices (ARM64) and it produced twice larger file (around 35Kb) than almost identical command-line on desktop (mac silicon, around 20Kb)...
0
votes
1
answer
105
views
Linking fails with: in function `main.cold': undefined reference to `__cxa_call_terminate'
I'm trying to build, using CMake, a program involving C++ and CUDA-C++ code. It used to build file, several months ago, but - now am getting a linker error I'm not familiar with:
in function `main....
0
votes
2
answers
84
views
gcc/g++ compiler with POSIX thread model
I'm on Windows OS and in the past month I used to compile a C/C++ project in Qt Creator IDE using MinGW's gcc/g++ compilers based on POSIX thread model, i.e. compilers that were built with the option -...
1
vote
0
answers
88
views
interrupt(): gate descriptor is not valid sys seg (vector=0x0X)
I am making my own UNIX like OS called Connor's UNIX and I am implementing kernel and userspace separation and I have been all day and this is as far as I can get it to work and if you need any more ...
1
vote
0
answers
90
views
Avoid non standard transitive includes in gcc / libstdc++ [duplicate]
The following code compiles in gcc15 with g++ -std=c++17
#include <iostream>
int main() {
int A, B;
std::cin >> A >> B;
auto v = std::tie(A, B);
}
However, this is ...
-1
votes
0
answers
67
views
i686-elf-gcc "Error: invalid instruction suffix for 'push'/'pop'" [closed]
I'm following the barebones guide on OSDev Wiki and I'm trying to compile my kernel.c file with
i686-elf-gcc -ffreestanding -O2 -m32 -c kernel.c -o kernel.o
but I constantly get the following ...
0
votes
1
answer
54
views
Unfreeable Memory when Using Capstone
I disassembled a 7,838,304-Byte portion of /usr/lib/x86_64-linux-gnu/dri/i965_dri.so using Capstone as shown below:
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#...
0
votes
1
answer
52
views
Linkage of Win32 api and custom GCC build (StrawberryPerl)
I try to build some source code containig Win32 API code with GCC 8.3.0 (i686-posix-dwarf) that comes with Strawberry Perl Portable package. It easily builds code, but struggles when it comes to ...
1
vote
0
answers
54
views
Recommended RStan compiler flags for gcc
I need to install RStan and I want to make sure that it's as efficient as possible. I'm using gcc. I'm reading this guide from 2022.
Luckily, the Stan developers built an option called STAN_CPP_OPTIMS
...
2
votes
0
answers
44
views
Best way to successfully compile GNU-pth as a 32-bit dynamic library under Linux?
Regardless of --build or --target, when configure points out the
I'm trying to compile GNU pth in 32-bits form under Linux.
Toolchain used:
Ubuntu 24.04.2 (VM)
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13....
Advice
0
votes
1
replies
42
views
Adding stack information to jit'd code for sanitization
Disclaimer: I'm expecting that the answer to this question will be that it can't be done, but I'm asking as a just in case.
I am working on a JIT'd language with the compiler and runtime implemented ...
0
votes
0
answers
40
views
Why DW_AT_language is C11 for -std=c17 (and higher)?
For -std=c17 (and higher) DW_AT_language is C11:
$ echo "int x;" | gcc -c -xc - -fPIC -o x.o -g -std=c17
$ gcc -shared -o x.so x.o
$ readelf x.so -w | grep -P '(DW_AT_language\s*:|DWARF ...
0
votes
1
answer
20
views
Getting address of special symbols in stripped ELF
I have a program targeting a small memory ARM R5 CPU, being compiled with gcc 11.2.0 and ld 2.37.20210721.
I have a critical symbol that I would like to know the address of, even if the binary was ...
Tooling
0
votes
0
replies
42
views
How do you set up GCC for Windows with the Windows 10 SDK?
A friend of mine has an application in C he has been helping to maintain, which he has been building for Linux, but he asked me to help build Windows binaries. The project has a Makefile.win32, so it ...