12
votes
A simple reusable class for rational numbers
For performance, I would suggest using gcd to simplify before multiplications / divisions. As an example:
...
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 ...
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 ...
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 ...
7
votes
Accepted
Rate my Makefile
Not Enough CFLAGS
You currently have c -W -Wall -pedantic -O3. First, -c shouldn’t be there;...
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 ...
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 ...
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, ...
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 ...
6
votes
Accepted
Makefile for a C++ project using Boost, Eigen, and htslib
Couple of things you do that don't match standards.
...
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:
<...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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 ...
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 (<...
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 ...
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 ...
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 ...
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
...
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 <...
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 ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
makefile × 98c++ × 36
make × 26
c × 24
beginner × 12
console × 5
python × 4
bash × 4
linux × 4
c++11 × 3
perl × 3
kernel × 3
java × 2
performance × 2
game × 2
unit-testing × 2
image × 2
file-system × 2
assembly × 2
boost × 2
portability × 2
x86 × 2
integration-testing × 2
cmake × 2
gcc × 2