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
3 votes
3 answers
313 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 ...
user avatar
  • 258
2 votes
2 answers
124 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. ...
user avatar
6 votes
3 answers
399 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 ...
user avatar
6 votes
2 answers
301 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 ...
user avatar
-7 votes
1 answer
102 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 ...
user avatar
6 votes
1 answer
2k 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 ...
user avatar
  • 313
4 votes
1 answer
737 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 ...
user avatar
  • 903
0 votes
3 answers
109 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 ...
user avatar
  • 1,868
3 votes
1 answer
109 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 ...
user avatar
  • 211
3 votes
2 answers
325 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 ...
user avatar
4 votes
3 answers
162 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 ...
user avatar
  • 1,868
5 votes
3 answers
621 views

Encapsulating snprintf to avoid repetition of sizeof

Correct usage of snprintf involves very long and repetitive lines: ...
user avatar
  • 1,868
8 votes
2 answers
834 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 ...
user avatar
  • 1,868
3 votes
0 answers
408 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 ...
user avatar
0 votes
1 answer
99 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. ...
user avatar
  • 103
2 votes
1 answer
274 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 ...
user avatar
2 votes
0 answers
68 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 ...
user avatar
3 votes
2 answers
860 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 ...
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 ...
user avatar
  • 19.9k
10 votes
1 answer
466 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: ...
user avatar
  • 191