All Questions
15,879 questions
4
votes
3
answers
70
views
GCC C99 Disable compilation of main() without return
How to force gcc compilator throw error when int main() have no return statement. This code compiles without any errors
#include<stdio.h>
int main(){
printf("Hi");
}
I am using
...
2
votes
0
answers
93
views
How can I force the compiler to keep my parameters in the same registers when returning?
I'm trying to write some weird code that I'm planning on using for a very simple JIT. It's a bunch of small bytecode handler functions that I'll use in the generated executable that will look ...
1
vote
1
answer
62
views
How to differentiate address sanitizer error from script error?
When using Address Sanitizer when either of ASAN or the actual program fails, the exitcode is always 1. How can I differentiate one from the other? I tried setting exitcode option in ASAN_OPTIONS to ...
2
votes
1
answer
84
views
Strange behavior of printf when converting a pointer to a double
I was trying to demonstrate what happens if you forget to dereference a pointer by printing a pointer to double double *pd with printf("%f", pd) (instead of using *pd).
I was expecting this ...
0
votes
4
answers
107
views
Usual Arithmetic Conversion in Arithmetic Operation
I am currently learning about type conversion in C, and I came across the concept of Usual Arithmetic Conversions in implicit type conversion.
Implicit type conversion, in which the C compiler ...
0
votes
1
answer
109
views
How do I tell gcc to shut up about forward declaring struct inside parameter list?
#pragma GCC diagnostic push
#pragma GCC diagnostic ignore ???
int fstat(int handle, struct stat *statbuf);
/* to get struct stat, #include <asm/stat.h> */
#pragma GCC diagnostic pop
I've ...
1
vote
0
answers
66
views
memcpy crash only on kernel 6.8.0-49 [closed]
The following code is written in a kernel module, and its behavior varies across different Linux kernel versions and compilers. The
memcpy(pulData, (PU32)&MailboxData.Data, sizeof(MailboxData.Data)...
-1
votes
1
answer
115
views
Some trash data written on my compressed files ( My own algorithm )
This is my program to compress data (it is free but has copyright for commercial usage) . This program suppose to read a file as data-number and find a huge nth root of file (depending on file size) ...
1
vote
1
answer
49
views
C header file /linux/if_arp.h has errors
When I compile my program it gives me errors for <linux/if_arp.h>. it keeps on giving me errors for re-declarations. I want to release my program soon , and I am not sure what I can do about ...
3
votes
2
answers
99
views
Why does the .data.rel.ro section takes so much space in my executable?
I want to build a shared library on Linux which contains a big initialized array and use this array in different executables.
I'd expect this to allow to reduce the compilation output size epecially ...
0
votes
3
answers
122
views
Is this a gcc bug? Function returns 0 when looping an int* over elements of a __m256i
When compiled with gcc the function sum_of_squares returns 0. Am I doing anything wrong or is this a gcc bug? I know that I am not handling cases when n is not divisible by 8.
#include <stdio.h>
...
1
vote
0
answers
43
views
How can I make GHashTable work with 64-bit hash?
I approached a problem when I tried to use XXH3_64bit from <xxhash.h> module over the wrapper with __fastcall for GHashTable initialization, but the type definition for GHashFunc requires the ...
2
votes
1
answer
62
views
Arm Cortex-M7 SAM-E70 x32-ld is keeping both weak and strong function definition
I am trying basic thing with SAM-E70 but proper documentation is not existing and after 6 hours not even GPT could help, so I am asking here. I need to be able to place function directly at vector ...
1
vote
0
answers
59
views
C program runs from command line, but won't by double click
I wrote a small C program as wrapper for .NET, compiled through gcc, which works on both Linux and Windows when run through the terminal or command line. Ideally I'd want it to start via double ...
-1
votes
0
answers
74
views
Vscode Makefile tools Extension - Cant' build a target
I have a task to debug a given project. When trying to build the makefile by the terminal, I can do it easily but, when trying to build a target with Makefile tools, I am getting the following error:
...
3
votes
2
answers
146
views
Negative value forced zero when assigned to uint16_t variable in C
I understand that unsigned and signed integers are just a different representation of the underlying bits according to two's complement. That is, the following is my observation -- b is a non-zero ...
1
vote
1
answer
112
views
checking environment variables in C
I am new to C (somewhat seasoned in Perl, from a long ago, and Lua more recently), and just can't figure out what goes wrong in trying to patch an old program written in C: I'd like it to set an ...
1
vote
0
answers
38
views
unknown type name 'SAL_acquire'
I am worknig on an application that runs on Windows 10 prompt. I am using Windows APIs, the program language is C and GCC as compiler. One year ago I was able to compile this project without errors, ...
2
votes
0
answers
72
views
linking gcc compiled c application to c and gfortran libraries
I am trying to link an application compiled with gcc 8.5.0 to c and Fortran libraries compiled with gcc 8.5.0 and gfortran (version unknown) on Oracle Linux (a RedHat derivative). Linking to the gcc ...
2
votes
1
answer
119
views
Math error conditions (C99, C11, etc.) in GCC
With ISO C99 onward we have a few macros (or constants) that help understanding how some math errors (see <math.h> related) are signaled. However, to me it looks like they haven't been ...
3
votes
2
answers
102
views
Is this inline asm correct for bitcasting int as float?
I am trying to familiarise myself with gnu inline assembly. I wrote a single line inline asm to reinterpret int as float. While this prints the correct result, I am wondering whether this is correct.
#...
1
vote
2
answers
77
views
Where are libc files located [duplicate]
When I write code such as
#include <stdio.h>
int main(int argc, char** argv) {
printf("Hello, world!\n");
return 0;
}
gcc imports stdio.h which in turn requires an associated ...
0
votes
0
answers
129
views
Invalid address in C
I ran a program like this
#include <unistd.h>
#include <stdio.h>
(*$$)() = 0x7ffff7e9a870;
$(){
$$(1, "Hello, World!\n", 14);
}
0x7ffff7e9a870 comes from another program or ...
5
votes
2
answers
129
views
Is warning yielded by -Wc++-compat about identifiers not yet expanded by macro a false positive?
I've been compiling my C code against some very "non-default" warnings and found a potential GCC bug - a false positive caused by -Wc++-compat. Before explaining anything, it would probably ...
1
vote
1
answer
81
views
How to improve gcc compile time for compile-once single file program
GCC version: 11.4.0
Flags I am passing: -O3 -march=native -funroll-all-loops -mprefer-vector-width=512 -mavx
I have a C program that looks like this:
void foo(...) {
for (int i...)
for (int j...)...
1
vote
4
answers
79
views
Make constant array visible to different source file
Is it possible to make contents of constant array be visible across multiple other source files so that compiler can optimize access to the array.
I have an array const int myTable[10]; and in ...
1
vote
2
answers
105
views
What is the rationale for 0-size arrays?
Both GCC and Clang support (as an extension) 0-size (also called "0-length") arrays.
What is the rationale for 0-size arrays (example int x[0])?
2
votes
2
answers
109
views
Why am I getting "Assuming signed integer overflow does not occur" here?
Code in question (godbolt)
#include <stdbool.h>
void do_work(void);
typedef struct task {
int timer;
void (*job)(void);
} task_t;
typedef struct task_list {
task_t *tasks;
int ...
0
votes
0
answers
63
views
Issues with using * in command line in windows [duplicate]
I was trying to solve the reverse polish calculator problem where the arguments can be entered on the command line. I am facing a peculiar problem. The program name is rpc.exe
A command line entry as ...
1
vote
1
answer
95
views
vectorisation fails due to unsupported control flow in loop
I have some C code that looks like (The full code on Compiler-Explorer: https://godbolt.org/z/aTGac8fco):
void foo(const float *restrict const input,
float *restrict const output,
...
6
votes
1
answer
118
views
Is the statement “Uninitialized global variables get weak symbols” in CSAPP accurate?
In Computer Systems: A Programmer’s Perspective (CSAPP), the book mentions that “Uninitialized global variables get weak symbols.” After some experimentation, I found this description seems ...
-1
votes
2
answers
66
views
While linking the assembly object file with GCC, relocation error occurs due to errno setting [duplicate]
as a school project I am asked to rewrite the write function in x86-64 assembly. There are some rules in this project. For example, just as write sets errno in case of an error, my write function ...
0
votes
2
answers
108
views
31 October skipped, why?
I expect the following code to write 31st October between 30th October and the 1st November.
My output skips the 31st.
Is it a bug? Do I misuse these functions?
I suppose I did something wrong, as I ...
1
vote
1
answer
130
views
How to tell GCC that it does not need to reload a value from memory after passing a pointer to a function with read-only access
Please consider the following program:
#include <stdio.h>
typedef char*(*g)(const char*)
__attribute__((__access__(__read_only__, 1)))
;
char *h(const char*)
__attribute__((__access__(...
0
votes
2
answers
73
views
How can I find the declaration of sin function in math.h file of GCC in Debian Linux?
I read about C programming language in Yashwant Kanetkar's book Let us C. In Functions chapter I read about sin, cos, tan and pow functions of math.h file. But in this chapter it is written that:
You ...
2
votes
2
answers
89
views
Why do I get an excess element warning in this tagged union in gcc C?
I am writing a tagged union in C, the definition is as follows:
struct uuid_0000000000061d0c {
long _0;
union {
struct {void* _1;};
struct {char* _1001; char* _1002;};
...
2
votes
1
answer
92
views
Can I access the first struct element without knowing what other elements are in it?
I suspect this is UB, according to ANSI, but on my system (x64 Linux), even with -Wall -Wextra -Werror -O3, both gcc and clang produce the expected result here:
#include <stdio.h>
typedef ...
2
votes
3
answers
233
views
How to tell the compiler a function argument will never be zero?
Imagine I have a dummy C function like this:
void Dummy(uint64* dest, const size_t count)
{
for (size_t ii = 0; ii < count; ii += 8) {
*dest++ = (uint64)dest;
}
}
If you look at what the ...
3
votes
2
answers
167
views
Segfault shellcode in main C
I'm trying to create a main. I compiled my code with:
$ gcc -g3 -o shellcode shellcode.c
But I always get a Segmentation fault (core dumped)
Using GDB, I see that the first instruction is executed ...
2
votes
1
answer
102
views
My program takes too long to start when there is an input needed from the user
I'm using Code::Blocks with the GCC compiler to write C programs as a first-year CS student. I encountered a strange issue when using scanf() in my programs.
The program compiles normally, but when I ...
6
votes
1
answer
113
views
Use of Stack-Local Variables in Naked Function
While browsing some vendor-supplied startup code for a commodity MCU and reading this excellent SO post about GCC's naked attribute, I seem to have come to a contradiction. The linked GCC ...
1
vote
1
answer
65
views
When is 'gcc -c' not enough to compile into a binary but needs 'gcc -o'? [closed]
I used to compile C programs with a command line like this:
gcc -c myexecutable mysource.c
After that I could run 'myexecutable' from shell. In the past this always worked for me.
With a tool that I ...
1
vote
0
answers
51
views
GCC can not load functions defined in dll.a library in windows: Calling Julia from C
I am trying to call Julia functions from C on windows. I followed the documentation from Julia and everything should work properly, but for some reason it does not. The main problem is that when I am ...
45
votes
3
answers
6k
views
An empty program that does nothing in C++ needs a heap of 204KB but not in C
Consider this empty program:
int main()
{ return 0; }
If I compile it with C++ with g++ main.cpp && strace ./a.out, and analyze the output with strace, I observed that the last lines of the ...
0
votes
1
answer
56
views
Structures inside custom section are inverted when compiling with aarch64-none-elf-gcc
When I compile using gcc for x86, the structures are placed in the section in the order I declare them. However, when I compile using aarch64-none-elf-gcc for an ARM target, the structures appear to ...
0
votes
0
answers
124
views
How to Ensure Compatibility of MinGW-Compiled DLLs on 32-Bit and 64-Bit Windows Systems?
I'm creating two proxied DLLs for wintrust.dll: one for 32-bit systems and another for 64-bit systems, using the gcc compiler from the MinGW64 and MinGW32 toolchains. The goal of these DLLs is to ...
1
vote
1
answer
131
views
How to force gcc to do printf checks on non-literal format strings?
const char* const non_literal_string = "Hello %d";
void my_print()
{
/*
* I would like GCC to throw a warning when compiling this line because the
* argument is not of int ...
1
vote
1
answer
48
views
Cortex-M loading 32-bit variable optimization
I'm trying to compile the following test code below, that only writes the 32-bits variable into a pointer. I write it once as byte access, and second time as word access.
void load_data_8(uint32_t ...
1
vote
0
answers
113
views
Linker Fails To Resolve External Pointer
I am trying to compile the following files using gcc (arm-linux-musleabi-gcc (GCC) 9.4.0), but the reference to json_start does not get fixed up correctly and incorrectly ends up as an offset rather ...
0
votes
0
answers
87
views
Old GCC 4.4.7 wasn't initializing randomly
I was compiling C legacy projects using:
gcc (GCC) 4.4.7 20120313
On a RedHat6 environment, pretty old.
Now I'm using:
gcc (GCC) 8.5.0 20210514
On a RedHat8 environment, which is better.
Flags were:
...