Skip to main content
Filter by
Sorted by
Tagged with
Advice
2 votes
4 replies
69 views

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 ...
user3195869's user avatar
3 votes
2 answers
186 views

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 ...
Devashish's user avatar
  • 193
Best practices
2 votes
10 replies
274 views

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 ...
Moi5t's user avatar
  • 465
3 votes
5 answers
627 views

I'm talking from a language point of view in C or C++, where the compiler sees: return condition ? a : b; vs: if (condition) return a; else return b; I've tried in my code, and both of them ...
Zebrafish's user avatar
  • 16.3k
25 votes
2 answers
4k views

The C++ standard [dcl.attr.likelihood] says: [Note 2: Excessive usage of either of these attributes is liable to result in performance degradation. — end note] I’m trying to understand what “...
Artyom Fedosov's user avatar
0 votes
0 answers
43 views

Nodes: building a gcc_tree_node for a custom prograimming language compile and base on C++26 the modules are avilable the language using tab-block system every keyword start with '/' I want to ...
Adam Bekoudj's user avatar
5 votes
3 answers
290 views

I thought that the noinline function attribute would force the compiler to treat a local function as a black box: __attribute__((noinline)) void touch_noinline(int&) {} void touch_external(int&...
sh1's user avatar
  • 5,010
2 votes
0 answers
61 views

Preparing to make Estrin's method vectorisable I changed from normal linear indexing of the coefficients to bitreversed and restricted it to strictly powers of 2. Neither MSVC nor ICX can see how to ...
Martin Brown's user avatar
  • 3,596
5 votes
1 answer
186 views

In the classic talk An (In-)Complete Guide to C++ Object Lifetimes by Jonathan Müller, there is a useful guideline as follows: Q: When do I need to use std::launder? A: When you want to re-use the ...
xmllmx's user avatar
  • 44.6k
1 vote
2 answers
190 views

The switch statements in the following two functions int foo(int value) { switch (value) { case 0: return 0; case 1: return 0; case 2: return 1; } } int ...
notgapriel's user avatar
4 votes
1 answer
151 views

I need (only) the real part of the product of two complex numbers. Naturally, I can code this as real(x)*real(y) - imag(x)*imag(y); or real(x*y); The latter, however, formally first computes the ...
Walter's user avatar
  • 45.8k
5 votes
1 answer
267 views

I mainly use clang, but I have also explored other compilers during my experiments, such as MinGW GCC and MSVC, but they all have this problem. E:\code\test>clang -v clang version 20.1.7 Target: ...
Moi5t's user avatar
  • 465
1 vote
2 answers
161 views

I'm writing a C function float foo(float x) which manipulates a floating-point value. It so happens, that I can guarantee the function will only ever be called with finite values - neither NaN's, nor +...
einpoklum's user avatar
  • 137k
4 votes
0 answers
120 views

MSVC seems to be taking the values from my array of coefficients and scattering them around in its .rdata section, not keeping them contiguous even though they're all used together. And it takes the ...
Martin Brown's user avatar
  • 3,596
13 votes
1 answer
1k views

#include <iostream> #include <new> struct A { int const n; void f() { new (this) A{2}; } void g() { std::cout << this->n; } void h() { ...
xmllmx's user avatar
  • 44.6k
31 votes
2 answers
5k views

In case of failure, malloc returns a null pointer. In the following code the latest GCC and clang assume malloc never fails and simple remove the branch #include <cstdlib> int main() { if (!...
Dmitry's user avatar
  • 1,649
2 votes
0 answers
96 views

I am currently reading through the F# core library source code and stumbled upon a common pattern which made me wonder a little about the performance of it, and could not find anything about it by a ...
kam's user avatar
  • 687
3 votes
2 answers
198 views

Say I have following C function: i64 my_comparator1(i64 x, i64 y) { if (x > y) { return 1; } if (x < y) { return -1; } return 0; } If I happen to know something about arguments that ...
KAction's user avatar
  • 667
1 vote
0 answers
114 views

I compile my binary like this go build -gcflags '-N -l', but when I run them in dlv I get Warning: debugging optimized function. My guess it's that it's a different host than the build host and the ...
Philippe's user avatar
  • 2,126
1 vote
4 answers
162 views

I have a variable which is read from my main loop, and is both read and written from an interrupt handler. The interrupt can change the value at any time, so clearly it needs to be volatile in the ...
Jack B's user avatar
  • 121
-2 votes
1 answer
174 views

I was really surprised that the code below types “res = 0” being compiled with optimization both on MSVC (the code) and Clang (the code) while it hangs (as expected) without optimization. #include <...
Damir Tenishev's user avatar
-2 votes
1 answer
76 views

I wrote an unoptimized C source code for matrix multiplication, and I want to test the optimization capabilities of the Clang compiler. void MatrixMul(unsigned int N, int *C, int *A, int *B) { ...
yinghao's user avatar
1 vote
0 answers
81 views

I would like to do some (micro)benchmarking in Swift. I have been using package-benchmark for this. It comes with a blackHole helper function that forces the compiler to assume that a variable is read ...
loonatick's user avatar
  • 1,197
0 votes
2 answers
632 views

I LITERALLY tried everything, when I do cargo clean and then cargo build , it takes almost 10 minutes to build because of rocksdb , below is my Cargo.toml file, I have only 2 or 3 files of code which ...
Gigin Parseh's user avatar
7 votes
1 answer
185 views

Consider the following code: void f1(bool ok) { if (ok) [[likely]] { // ... } else [[unlikely]] { // ... } } void f2(bool ok) { if (ok) [[likely]] { // ... ...
xmllmx's user avatar
  • 44.6k

1
2 3 4 5
69