Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [gcc]

For code written to be compiled specifically by the GCC, which stands for the GNU Compiler Collection. Developers often compile several languages using this compiler collection.

Filter by
Sorted by
Tagged with
7 votes
2 answers
659 views

Consolidating GNU C's and C23's attributes

C23 has introduced attribute specifier sequences. Consequently, the header below attempts to conditionally define macros for these sequences (for my own use cases). In cases where a compiler does not ...
Harith's user avatar
  • 6,872
4 votes
1 answer
162 views

32x32x32 units octree, that supports 15-bit data units

The idea is to have an octree that stores a 32x32x32 region of 15 bit values more efficiently than a 32x32x32 array, because if all 8 leaf nodes of a given branch are the same, the branch does not ...
CPlus's user avatar
  • 928
6 votes
2 answers
4k views

128-bit integer type in GCC/Clang

When working on my projects, I often need a 128-bit integer type. For this purpose, I use the __int128 compiler extension. Here is the implementation I am currently ...
DaBler's user avatar
  • 309
3 votes
3 answers
977 views

Efficiently read a file into a (C) string using POSIX APIs

Exactly what the title says, this is a C++ class that attempts to read a file into a null-terminated string as efficiently as possible, using POSIX APIs. Obviously this is not intended to be portable ...
Ray Hamel's user avatar
  • 258
3 votes
2 answers
277 views

Reference-counted smart pointer in C

About I've been experimenting with gcc's __cleanup__ attribute, and thought it'd be a great fit for a memory-safe smart pointer for C. This is the implementation. ...
Ricardo Silva's user avatar
6 votes
3 answers
560 views

4 different implementations of modulo with fully defined behavior

I've implemented the 3 variants of the modulo operation described on this Wikipedia page. The goal is to have fully defined behavior for all inputs. Code Implementation with truncated division (result ...
Cl00e9ment's user avatar
6 votes
2 answers
1k views

Bash script - compile and run c++ code for coding competitions

This is a simple bash script that I use to compile and run single C++ files for coding competitions. Features: Detects if there is a corresponding .in file next to ...
thesilican's user avatar
-7 votes
1 answer
133 views

Can you please give feedback on my C++ Code? [closed]

Can you please give feedback on my C++ code so I can get better at writing code? I want a code that is well written. This Code uses the cstdio include for good performance and cstdint include because ...
Heyexclamation's user avatar
10 votes
3 answers
6k views

C++ Template to implement the Factory Pattern

Design A template class that will create a concrete instance of an interface class when given the name (as a string) of the concrete class. This design is often seen in code, so the purpose of this ...
Blue7's user avatar
  • 373
4 votes
1 answer
1k views

Macro for counting number of elements in an array

We all know the classic version of counting the number of elements in a C array: sizeof(a)/sizeof(*a) But this is dangerous, because if used on a pointer it will ...
klutt's user avatar
  • 903
0 votes
3 answers
121 views

Safer & simpler allocation functions and macros

I wrote a bunch of functions and macros for safer and simpler allocation. They are documented in their files. Disclaimer: The library requires POSIX extensions, GCC extensions, and LIBBSD ...
alx - recommends codidact's user avatar
3 votes
1 answer
138 views

Clang preprocessor concatenates an extra space vs. gcc - standard C99

I maintain a C library project both on gcc and clang. I am looking for advice on how to make the following macros more portable, terse, readable or standard abiding. When I compile ...
OneArb's user avatar
  • 211
3 votes
2 answers
396 views

A little C++ program to have timed rounds for a game

I know it could be better, but I’m new to C++, so I don’t know many of the tricks, along with some of the includes that are already obsolete. This program asks for names as input, adds a time for ...
ProjectArrow's user avatar
4 votes
3 answers
387 views

Encapsulating snprintf to simplify usage: sbprintf & swnprintf

After writing swnprintfand sbprintf in C (Encapsulating snprintf to avoid repetition of sizeof), I've written a C++ version of ...
alx - recommends codidact's user avatar
5 votes
3 answers
1k views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
alx - recommends codidact's user avatar
12 votes
3 answers
1k views

Register "%b" conversion specifier

I'm writing a library to register the b, B conversion specifiers and make them work the closest possible to ...
alx - recommends codidact's user avatar
3 votes
0 answers
673 views

Generic Makefile for C projects

I'm trying to create a generic Makefile that will work with the following directory structure: Project Directory Makefile main.c source file source directory Source files include directory Header ...
dylanweber's user avatar
0 votes
1 answer
108 views

gcc constant time implemenation [closed]

I need to make the following function time constant - I have already removed if statements and have written it down to one line in the loop. ...
jonnyx's user avatar
  • 103
2 votes
1 answer
459 views

Printing 64-bit decimal numbers in freestanding environment

I need to print signed 64-bit numbers in decimal form. Program runs in freestanding environment (no C library available, libgcc may be unavailable too, or may not work correctly). So I can't use ...
Kirill Frolov's user avatar
2 votes
0 answers
75 views

String to long double conversion using FBLD

I always wanted to try fbld x87 instruction to aid to convert string to floating point value. I sure a chance to face this instruction in disassembly of all the ...
Tomilov Anatoliy's user avatar
3 votes
2 answers
976 views

Makefile for a small JNI project

So I'm going to publish this small project on GitHub and I thought I'd better do a makefile for it. The source code consists of 1 Java Class 1 Native JNI module written in C 1 stdlib wrapper object ...
Rodney's user avatar
  • 193
11 votes
1 answer
1k views

Computing average without overflows and with half-decent precision

At some point I needed to compute the average of a big collection of integers. I knew the size of the collection prior computation, but a naive average computation was prone to integer overflow while ...
Morwenn's user avatar
  • 20k
10 votes
1 answer
672 views

Vectorizing the product of an array of complex numbers

I am trying to write fast/optimal code to vectorize the product of an array of complex numbers. In simple C this would be: ...
Simd's user avatar
  • 191