42,278 questions
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>
#...
19
votes
9
answers
26k
views
Visual C++ equivalent of __FILE__ , __LINE__ and __PRETTY_FUNCTION__
GCC compiler gives me the following macros:
__FILE__ so that I can print out the file name + directory.
__LINE__ so that I can print out the line number of where I'm printing from.
__PRETTY_FUNCTION__ ...
11
votes
1
answer
620
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&...
10
votes
1
answer
2k
views
How -fvisibility-inlines-hidden differs from -fvisibility=hidden in gcc
According to http://gcc.gnu.org/wiki/Visibility,
With -fvisibility=hidden, you are telling GCC that every declaration not explicitly marked with a visibility attribute has a hidden visibility.
And
...
1
vote
0
answers
55
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
...
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 ...
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
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;
...
-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 ...
35
votes
5
answers
35k
views
How can I determine if the operating system is POSIX in C?
Related questions
How can I detect the operating system in C/C++?
How can I find out what operating system I am running under in GCC or in ANSI C?
I'd be fine If I can know if I'm running on POSIX.
...
8
votes
1
answer
10k
views
getting ld to ignore undefined references when making a DLL
I'm trying to get gcc's ld to ignore unresolved references when putting together a shared library from a bunch of object files compiled with -fpic flag.
I tried a bunch of options so far such as (...
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
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 ...
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 ...
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 ...
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 ...
13
votes
3
answers
19k
views
How do I identify x86 vs. x86_64 at compile time in gcc?
I want to compile part of my code only on x86 and x86_64 linux, but not s390 linux or others. How to use the macro define in C to achieve it? I know linux is to determine linux OS, and 386, 486 and ...
3
votes
3
answers
670
views
Templated is_in() function (check if array contains string) in C++
I would like to do the following:
std::string b = "b";
is_in("a", { "a", "b", "c" });
is_in("d", { "a", "b", "c&...
15
votes
1
answer
10k
views
Why glibc and pthread library both defined same APIs?
Why glibc and pthread library both defined same APIs ? Here is the snapshot
ubuntu@ubuntu:/lib$ objdump -T /lib/i386-linux-gnu/libc.so.6 |grep pthread_cond_signal
000f8360 g DF .text 00000039 ...
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)...
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 ...
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....
2
votes
1
answer
9k
views
MinGW stdio.h : No such file or directory
i know that there are some other posts with this problem but the solutions that where given weren't helpful for me.
I just installed MinGW on my Windows 7 laptop.
So i wrote a hello world program to ...
0
votes
2
answers
2k
views
How can I properly install cs50.h Library on OS X 10.10.1?
I'm attempting to install the cs50 library
https://manual.cs50.net/library/#mac_os so that I can compile c code for the class on my OS X 10.10.1. Unfortunately, I'm having some problems.
Let me walk ...
6
votes
1
answer
12k
views
Building simple DLL with MinGW
I've read everything here and everything I can find on the net about doing this, but the information is out-of-date, contradictory, or inapplicable. I have a very simple library in C, which I compile ...
18
votes
5
answers
9k
views
How to deprecate a C pre-processor macro in GCC?
I know how to use __attribute__((deprecated)) or [[deprecated]] to deprecate a function like this:
int old_fn() __attribute__ ((deprecated));
[[deprecated]] int old_fn2();
But how to deprecate a ...
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 -...
0
votes
2
answers
148
views
Does -Wpedantic make the program follow the -std=version?
If I use gcc -std=c17, will -Wpedantic issue warnings for C17? Is this the same as ISO C?
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 ...
11
votes
2
answers
15k
views
What's the difference between '-Wextra' and '-pedantic' in gcc?
Or - who is "stricter"?
From what I've read, both flags add extra warnings, not included in '-Wall', but what distinguish them?
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 ...
2
votes
1
answer
2k
views
How can I separately build and develop libgomp (openMP runtime)?
I am trying to make changes to the openMP runtime library (GOMP). As far as I know, the library comes with GCC compiler but my goal is to work on GOMP alone. So I wonder how I can build and develop ...
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....
3
votes
2
answers
570
views
Automatically know if a GCC/Clang warning comes from Wall or Wextra?
I wonder if there's some clever, automatic way of knowing if a particular compiler warning (e.g. -Wunused-parameter) comes from the group -Wall, -Wextra, or another group, for both GCC and Clang.
Use ...
17
votes
3
answers
4k
views
Can I use Thread Sanitizer for OpenMP programs?
Consider the following example:
#include <iostream>
int main () {
int i = 0;
#pragma omp parallel
{
#pragma omp critical
{
++i;
}
}
std:...
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
vote
2
answers
2k
views
gcc / g++ command does nothing and exits with code 1
gcc / g++ throws exit code 1 and does nothing
I tried to compile my c++ / c files using gcc / g++ !
It did nothing
the command neither produced a.exe file
it didn't throw any error ,(print anything ...
1
vote
2
answers
151
views
C Language: Triple nested while() loop that does not work correctly
I want to write a code in C language to output a list of triples matching the Pythagorean triple in a range of positive integers (a2 = b2 + c2 with a, b and c ∈ ℤ+) using only nested while () loops.
I ...
12
votes
4
answers
9k
views
How to stop GCC complaining about "directive output may be truncated" in snprintf() call?
I'm using GCC 9.2.0 on both an ancient Linux (RedHat 5.2) and modern macOS 10.14.6 Mojave, and I get the same complaint on both.
#include <stdio.h>
#include <time.h>
struct Example
{
...
18
votes
3
answers
2k
views
How can modern compiler optimization convert recursion into returning a constant?
When I compile the following simple recursion code with g++, the assembly code simply returns i, as if g++ can do some algebra tricks as humans can.
int Identity(int i) {
if (i == 1)
return 1;
...
0
votes
1
answer
143
views
gcc complains about braces in initialiser (nested structs)
In chasing down a very opaque bug, I have been trying to compile with no warnings or errors. This part of my code worked fine, but gcc complains about the braces; it says there are braces missing and ...
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 ...
1
vote
1
answer
914
views
Unable to get rid of -Wfree-nonheap-object warnings
I am trying to migrate code from older gcc (7.5.0)
to newer 11.3.0. All working, tested code, but I am not able to get rid of some warnings (I use -Werror) like:
warning: ‘free’ called on pointer ‘...
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 ...
80
votes
12
answers
208k
views
What does this GCC error "... relocation truncated to fit..." mean?
I am programming the host side of a host-accelerator system. The host runs on the PC under Ubuntu Linux and communicates with the embedded hardware via a USB connection. The communication is performed ...
11
votes
2
answers
6k
views
Variadic macro without arguments
I am using some logging macros, which are supposed to print out the information provided by the __PRETTY_FUNCTION__ macro and if needed name and value of up to two arguments.
A simplified version of ...
Advice
2
votes
10
replies
395
views
Visual studio vs gcc
I'm a small-scale C programmer at the moment, and I'm bugged by the question: is Visual Studio worth the annoyance that it is?
I've been programming in C and C++ in Visual Studio Code for a while, and ...
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 ...
5
votes
1
answer
143
views
Use std::regex_search called from module
I came across a strange problem. I made a C++20 module with the following content (file module.cppm):
module;
#include <regex>
#include <string>
export module foo;
export namespace bar {
...
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 ...