Skip to main content
12 votes

A simple reusable class for rational numbers

For performance, I would suggest using gcd to simplify before multiplications / divisions. As an example: ...
Justin Chang's user avatar
  • 2,447
10 votes

A simple reusable class for rational numbers

Value range class Fraction { public: ... private: int numerator, denominator; }; Most platforms define int to be 32 ...
Nayuki's user avatar
  • 1,369
10 votes
Accepted

Makefile for a tiny C++ project

nit: spacing CXX=g++-12 Bash requires squishing together FOO=value. But in a makefile we can make it slightly easier to read by ...
J_H's user avatar
  • 42.3k
9 votes
Accepted

A simple reusable class for rational numbers

Overview: Note sure it is best to reduce on every construction. That may be a bit expensive. I see a couple of places where every mathematical operation creates an object. I would reduce before ...
Loki Astari's user avatar
  • 97.7k
7 votes
Accepted

Rate my Makefile

Not Enough CFLAGS You currently have c -W -Wall -pedantic -O3. First, -c shouldn’t be there;...
Davislor's user avatar
  • 9,115
7 votes
Accepted

Makefile to build and test a C program

specification make shalt build ... Writing down requirements in English can be very helpful, keep doing it. But please spell it "shall". In KJV it ...
J_H's user avatar
  • 42.3k
7 votes

Makefile for a tiny C++ project

Generally, I would use as much of the make built-ins as possible. Specifically: I would normally not specify the C++ (or C) compiler. The default for gnu make is g++; the system should be set up to ...
Peter - Reinstate Monica's user avatar
7 votes

Makefile for a tiny C++ project

The biggest problem I see is that it doesn't handle dependency files. You can ask gcc (and MSVC!) to output an auxiliary file containing a Make-style dependency specification listing all input files, ...
Simon Richter's user avatar
7 votes
Accepted

Makefile for a tiny C++ project, follow-up 1

Consider this rule, which almost duplicates the built-in commands: $(PROGRAM).o: $(PROGRAM).cpp $(CXX) -c -g $(CXXFLAGS) $(PROGRAM).cpp -o $(PROGRAM).o The ...
Toby Speight's user avatar
  • 88.3k
6 votes
Accepted

Makefile for a C++ project using Boost, Eigen, and htslib

Couple of things you do that don't match standards. ...
Loki Astari's user avatar
  • 97.7k
6 votes

Simple VGA driver for a toy kernel

Makefile review We're missing the instruction to tell Make to remove partial results from failing rules; all Makefiles should somewhere contain .DELETE_ON_ERROR: <...
Toby Speight's user avatar
  • 88.3k
6 votes
Accepted

Command-line Tower of Hanoi game

General Observations Interesting! Decent job of coding. The partitioning of the code seems pretty good, but it can be improved. In the display of towers, the towers should be numbered so that the user ...
pacmaninbw's user avatar
  • 26.1k
6 votes

Makefile for a tiny C++ project

In addition to all the things that the other contributorors have mentioned: the first target of a Makefile is its default target, i.e. the one that gets built if ...
Guido Flohr's user avatar
5 votes
Accepted

Simple VGA driver for a toy kernel

To complement the Makefile review, here are a few more points that may help you improve your program. Use VPATH make already ...
Edward's user avatar
  • 67.2k
5 votes

Command-line Tower of Hanoi game

In addition to pacmaninbw's excellent answer, I'd like to add: Avoid using system() system() is very expensive: it has to fork ...
G. Sliepen's user avatar
  • 69.3k
5 votes

Writing a generic makefile for C projects

This looks wrong: $(target): $(objs) | $(obj-dir) $(COMPILE.C) -o $@ $^ Make predefines $(LINK.c) for this command.
Toby Speight's user avatar
  • 88.3k
4 votes

Avoid --compiler-options in makefile using nvcc

There are two different problems. One is to pass the same options to gcc and to gcc via nvcc (the accepted solution). The other is to pass several options without repeating the long command. The ...
alfC's user avatar
  • 198
4 votes

Find the greatest common divisor, with unit tests

The dependencies of gcd.h and test.h are missing. If you modify them, the objects would not be rebuilt. Stem rules let you avoid ...
vnp's user avatar
  • 58.7k
4 votes
Accepted

x86 Single Stage Bootloader

check_a20 has two bugs in it. First, you not comparing with the correct memory addresses. The physical address for the real mode ...
1201ProgramAlarm's user avatar
4 votes

x86 Single Stage Bootloader

Review of the Makefile: There's no .DELETE_ON_ERROR target. I know of no good reason to write a Makefile without that. Put the makefile in the target directory (<...
Toby Speight's user avatar
  • 88.3k
4 votes
Accepted

Generic makefile for C++ projects

It's reasonable to require GNU Make - it's available on all platforms that have their own Make (as far as I know), and trying to cope with the vagaries of all vendors' Make implementations is an ...
Toby Speight's user avatar
  • 88.3k
4 votes

std::vector<bool> workaround in C++

If you aren’t reinventing the wheel as a learning exercise, and want to code this productively, the simplest options are to use the Boost version of ...
Davislor's user avatar
  • 9,115
3 votes

std::vector<bool> workaround in C++

Makefile review: All makefiles should have .DELETE_ON_ERROR: to ensure erroneous output doesn't satisfy dependencies. The targets ...
Toby Speight's user avatar
  • 88.3k
3 votes
Accepted

Compiling and running a program to generate fractal images

Your chmod needs to go away; d.sh should already have the correct permissions, including when extracted from a source archive ...
Reinderien's user avatar
  • 71.1k
3 votes
Accepted

Optimization of General Purpose Makefile

Instead of defining your own compiler variable, I would override the implicit CXX variable. This also goes for the implicit <...
FromTheStackAndBack's user avatar
3 votes

Calculating effective shop inventories from CSV files

Bug The output, shop_stock_total.csv, contains the following lines, each of which is a tuple of (item, shop, quantity available, quantity available excluding ...
200_success's user avatar
3 votes
Accepted

Calculating effective shop inventories from CSV files

I see a number of things that may help you improve your program. Don't abuse using namespace std Putting using namespace std ...
Edward's user avatar
  • 67.2k
3 votes

Updating my package version using only a Makefile

I think there's an easier way to get this done: Extract the semver part from the tag (as you already did) Use conditionals to determine the field to increment Use a single Awk to increment the ...
janos's user avatar
  • 113k
3 votes
Accepted

Mocking socket calls in C++

This is a worthwhile task - I'm a firm believer in maximising my opportunities for automated testing. It tends to increase my peers' respect for my code, as they know they are less likely to find ...
Toby Speight's user avatar
  • 88.3k
3 votes
Accepted

(Rev. 2) Command-line Tower of Hanoi game

It's great to see all the improvements you've incorporated into your game! Clearing the screen As much as I would like to find a safe and portable alternative for ...
G. Sliepen's user avatar
  • 69.3k

Only top scored, non community-wiki answers of a minimum length are eligible