Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
0 answers
97 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 ...
csjh's user avatar
  • 192
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 ...
LuC's user avatar
  • 403
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])?
pmor's user avatar
  • 6,255
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 ...
MWB's user avatar
  • 12.4k
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 ...
Lance E.T. Compte's user avatar
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 ...
Parminder Singh's user avatar
5 votes
2 answers
140 views

Why -Wunused-value does not catch a statement `true;`?

Given following C code: #include <stdbool.h> int main (void) { true; return 0; } I expect that -Wunused-value would cause a warning at line 5: true; because this statement does ...
sleeptightAnsiC's user avatar
1 vote
1 answer
211 views

Is it possible to build sqlite extensions on Apple Silicon using clang?

I am attempting to build the percentile sqlite extension on an M1 laptop using the instructions on the page: gcc -g -fPIC -shared percentile.c -o percentile.so However, that results in the following ...
merlin2011's user avatar
  • 75.1k
-1 votes
1 answer
55 views

Using __atribute__((noreturn)) on loops?

Is there a compiler attributes (clang / gcc) that does something like noreturn but for loop? Something like: __atribute__((loopsnoreturn)) for (int i=0; i<12; i++) { if(i==5) return 0; //< ...
gberth's user avatar
  • 744
0 votes
2 answers
232 views

Use libgcc/compiler-rt altrenative with GCC/Clang

I am writing small low-level runtime library for fun. According to the libgcc website, low-level runtime library are libraries that compilers generates calls to its routines whenever it needs to ...
Andrej's user avatar
  • 29
0 votes
0 answers
119 views

Remove unused data from bss restored section (c)

I've noticed that when using -ffunction-sections -fdata-sections and -Wl,--gc-sections, unused restored BSS sections are still mapped into memory, even though I expect them to be stripped. Why are ...
Sababoni's user avatar
  • 5,097
12 votes
2 answers
2k views

Logical AND (&&) does not short-circuit correctly in #if

For code: #if defined(FOO) && FOO(foo) #error "FOO is defined." #else #error "FOO is not defined." #endif MSVC 19.38 prints: <source>(1): warning C4067: ...
Harith's user avatar
  • 7,315
3 votes
0 answers
106 views

Did gcc and clang accidentally drop C99 sequence point conformance?

Background: C99 6.5 §2 said: Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value ...
Lundin's user avatar
  • 212k
5 votes
3 answers
225 views

How to make compiler warning about the enum type mismatch in switch and case?

For the following code, I hope there is a warning because a is type enum A, but the case B1 and B2 are type enum B; but I couldn't find a way to make gcc/clang warn about it. Any suggestion on how to ...
lidaobing's user avatar
  • 1,075
1 vote
1 answer
239 views

GCC "labels as values" – intended usage

I recently heard about the Labels as Values extension to C/C++ in GCC and other compilers. I was thinking about how I'd use that to write a threaded interpreter (where a virtual machine program is ...
bobtato's user avatar
  • 1,229
3 votes
2 answers
149 views

Compiler doesn't issue warning on `uint64_t` under strict C89 mode

I'm trying to write strict ISO C89-compliant code. Since long long is not standard and is often implemented as compiler extensions before C99, the compiler should warn me it when I use it. However, ...
R-R's user avatar
  • 65
1 vote
1 answer
191 views

Using FSIN through inline-assembly

I want to use x87's FSIN through gcc's / clang's inline assembly. How would a sin()-function using an __asm__-block internally for that look like with a 64 bit double parameter ? Using __builtin_sin() ...
Edison von Myosotis's user avatar
0 votes
1 answer
59 views

On RPi 4 GCC and CLANG use 16-bit loads

This is simplified from a larger example. In the C source, I have: uint32_t xx = oxdeadbeef ; I compiled with gcc -O or clang -O Looking at 'objdump -d a.out' on the RPi 4, I see 9ac: 5297dde8 ...
tomdean1939's user avatar
1 vote
2 answers
93 views

Does C standard define the calling convention?

Does the C standard define the calling convention? I find the calling convention cdecl stands for C declaration, but i can’t find anything about it in the C stardard draft.
Jollioke Muzaom D's user avatar
7 votes
2 answers
175 views

In standard C, is the expression "i = (i = 1) + 1;" well defined?

In standard C, is the expression i = (i = 1) + 1; well defined? What's the difference between it and i = ++i + 1; from the perspective of sequence points? Someone told me there is a sequence point ...
Jollioke Muzaom D's user avatar
1 vote
0 answers
90 views

Differences in Compilation Results Between GCC and Clang

I encountered a situation where my C code compiles successfully with GCC but generates errors when compiled with Clang. Here is my C code: #include <stdio.h> #include <stdlib.h> #include &...
Konvt's user avatar
  • 63
0 votes
0 answers
97 views

Why there is segment fault when compile with clang15

Given the following code, built on x86 clang, and run, it will segment fault. #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <string.h> #include <sys/...
calvin's user avatar
  • 2,907
1 vote
0 answers
95 views

Diff in `-Bsymbolic` behavior between gcc and clang?

Could it be that clang and gcc somehow implement -Bsymbolic differently? \\ exe.c void f(); typedef void (*fptr)(); void compareFuncPtrs(fptr); int main() { compareFuncPtrs(f); return 0; } \...
Ofek Shilon's user avatar
  • 16.1k
0 votes
0 answers
66 views

How compile program with openMP functions?

I tried to run the code related to OpenMP and parallelization on mac m1, but I ran into a number of problems. The usual connection of the header file <omp.h> didn't work in VSC, so I installed ...
Ilya Suharenko's user avatar
1 vote
0 answers
82 views

C pointers and -O3 optimized semantic anomalies [duplicate]

Code #include <stdint.h> #include <stdio.h> void func(uint64_t* pInst) { *pInst = 0xffffffffff; *pInst = *(uint32_t*)&(*pInst); uint64_t Ret = *pInst; printf ("...
Xiang.Zuckerbird's user avatar
0 votes
0 answers
109 views

Preprocessing C code to only use C23 attribute notation

Is there a way for GCC/Clang/a C pretty-printer tool to preprocess/pretty-print a source file, using only the "new" (C23) attribute notation? In other words, transform this code: int a ...
anol's user avatar
  • 8,893
-1 votes
1 answer
134 views

Use gcc in mac instead of clang

I have a mac with Ventura 13.5.1 (intel proc). I need to usc gcc instead of clang in mac, how i can do it? Now i have smth like this on my mac: λ ~/ gcc -v Apple clang version 14.0.3 (clang-1403.0.22....
Nikolay's user avatar
-1 votes
1 answer
162 views

Have two C compilers

I wanted to set up C language on VSCode, and ended up with 2 compilers (clang and gcc) how can I delete one of them ? P.S: I'm using M2 Mac, had to notice that I want a solution to my problem, maybe ...
Aboud Fialah's user avatar
0 votes
2 answers
219 views

Consolidating GNU C's and C23's deprecated function attribute

The problem I am facing when using the below macro // Assume that __GNUC__ or __clang__ is defined. #if defined(__has_c_attribute) #if __has_c_attribute(deprecated) #define ...
Harith's user avatar
  • 7,315
0 votes
2 answers
178 views

buffer overflow attack works when compiled using clang but not when compiled using gcc

char shellcode[] = "\xeb\x18\x5e\x31\xc0\x89\x76\x08\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xe3\xff\xff\xff/bin/sh "; char large_string[128]; ...
michael101's user avatar
0 votes
2 answers
331 views

Is there a way to pass ownership of a pointer in C (like in Rust)?

I was looking for a way in C to prevent the usage of a pointer after it's ownership is passed to another function, where I can specify explicitly which parameter of a function should do that. Is there ...
Brendon Mendicino's user avatar
2 votes
2 answers
99 views

C preprocessor macro and warning suppression for custom variadic-argument function?

I am attempting to create a class of functions which can be called with any number and any type of arguments--similar to printf, but with one key difference: I would like to cast all arguments to ...
Oh Fiveight's user avatar
13 votes
1 answer
3k views

Possible Bug in GCC Sanitizers?

I always compile my programs with gcc and during development always with: gcc -g -Wall -Wextra -std=c2x -fsanitize=address,undefined Today I noticed that the address sanitizer randomly detects SEGVs ...
ben's user avatar
  • 131
2 votes
0 answers
83 views

Parsing C code to generate a flattened equivalent

I need to parse C code to generate a "flattened" Prolog readable form for static analysis purposes. e.g. int map (int den, int a) { den = den*(a+a); if (den == 90) return -1/(den-90); ...
Echancrure's user avatar
1 vote
0 answers
94 views

Is there a GCC/Clang attribute to mark which fields in a struct that a given mutex covers?

I'm thinking about how I would theoretically implement a multi threaded queue from first principles, using only glibc on POSIX. Obviously, this is going to require a mutex (or some other locking/...
ijustlovemath's user avatar
4 votes
2 answers
549 views

Why was the C compiler unable to compile code with an inline function?

It looks extremely weird, but I was unable to compile following simple code: inline void inline_func() {} static inline void static_inline_func() {} void some_func() { // THERE IS A PROBLEM with &...
lol lol's user avatar
  • 491
1 vote
2 answers
2k views

Why can I declare a variable after a label in GCC, but not Clang?

I found some code that compiles under gcc but not under clang: #include<stdio.h> int main(int argc, char **argv) { int test = 0; if (test == 0) { goto print_five; } else { ...
Ethan Smith's user avatar
1 vote
2 answers
383 views

What kind of warnings is -isystem in gcc supposed to ignore?

Several blogs, tutorials and GCC's documentation have lead me to believe -isystem can be used to ignore warnings in header files. A simple test suggests otherwise. #include <liburing.h> int ...
Unmanned Player's user avatar
0 votes
1 answer
142 views

How to tell GCC/Clang optimizer to generate specific sequence of operations

I have a loop that needs to execute sequences of operations in a specific order. What I am doing here is manually unrolling the loop a number of times: loop { delta = get_delta(); sum1 += ...
user avatar
0 votes
3 answers
106 views

Arithmetic which gives the lowest 64 bits on overflow

In C unsigned integer arithmetic wraps around on overflow and signed arithmetic is undefined on overflow. I would like to have 64 bit integer arithmetic (+,-,*) so that on overflow the result is the ...
Simd's user avatar
  • 21.2k
5 votes
1 answer
209 views

Should GCC/Clang optimize this redundant load via an array of restrict-qualified pointers?

I am looking into optimizations permitted for a compiler by adding the C99 restrict type qualifier to the type parameter of an array. For example, consider the function f below: int f(int* restrict a[...
Ties's user avatar
  • 51
0 votes
1 answer
142 views

Why clang and gcc output different results under `-std=c89` option?

I came across this quiz, so want to verify it myself: #include <stdio.h> void print_sum(a, b) { printf("%d\n", a + b); } int main(void) { print_sum(1.5, 8.5); return 0; } ...
Nan Xiao's user avatar
  • 17.4k
1 vote
0 answers
147 views

How to compile and deploy OpenSSL using osxcross on Linux

I need help compiling OpenSSL using osxcross and running that on a MacOS system. I managed to download the latest OpenSSL version from Github (3.1.4) and I compiled it using the following command: CC=...
Saleem gagguturu's user avatar
0 votes
0 answers
111 views

Mapping between line:column numbers in C or C++ code before and after preprocessing

When there's a syntax error in a C or C++ source file, both GCC and Clang report the exact line and column of where the error is. For example, if we try to compile this code fragment: #include <...
Bass's user avatar
  • 5,268
2 votes
1 answer
428 views

Is there any sanitizer setting in GCC or Clang that can detect the use of uninitialized heap-allocated memory?

These C and C++ programs use uninitialized memory: C: #include <stdio.h> #include <stdlib.h> int main(void) { double* p = malloc(100*sizeof(double)); printf("%f\n", p[...
MWB's user avatar
  • 12.4k
1 vote
1 answer
396 views

Clang uses a linked shared lib to decide which symbols to export?

Take this toy code for an executable and a shared library: // main.c void foo() {} int main() { return 0; } // bar.c void foo(); void bar() { foo(); } Let's build without optimizations, first with ...
Ofek Shilon's user avatar
  • 16.1k
8 votes
1 answer
302 views

gcc and clang emit seemingly redundant function call

typedef struct foo { void (*const t)(struct foo *f); } foo; void t(struct foo *f) { } void (*const myt)(struct foo *f) = t; foo f = {.t = t}; int main(void) { f.t(&f); myt(&...
user1806687's user avatar
7 votes
1 answer
810 views

malloc attribute takes no arguments

I've created a pair of functions: void destroy_foo(void *ptr); void *create_foo(void); As the names suggest, these function akin to malloc and free. I'd like to use the malloc gcc function attribute ...
Daniel Walker's user avatar
0 votes
1 answer
80 views

Forcing linking through the PLT

I just did a quick benchmark of the PLT overhead, and I found I'm unable to force my functions to go through the PLT in the final executable unless I put the code in a shared library and link that. ...
Petr Skocik's user avatar
0 votes
1 answer
466 views

Is __attribute__ portable across compilers?

I want to make sure my program works on either. Currently, I compile as such: CFLAGS := -std=c99 -Wall -Wextra -Wshadow -Wpedantic and want to make sure it works on either Linux/macOS. I use ...
user129393192's user avatar

1
2 3 4 5
12