gl_basecamp's People
gl_basecamp's Issues
Some notes
Good implementation. Seems you're absolutely confident with C.
Below are some comments on possible ways to improve the code yet more
GL_BaseCamp/01-L-Introduction
GL_BaseCamp/01-L-Introduction/main.c
Lines 16 to 19 in 59705ea
Now we have C11 and it could be done with variable-size declaration:
int grid_array[][] = {
{ 0, -1, -1, -1, -2, -1, -2 },
{ -2, -1, -1, -1, -1, -2, -2 },
{ -2, -1, -1, -1, -1, -2, -2 },
{ -2, -2, -1, -1, -1, -2, -1 },
{ -1, -2, -2, -2, -1, -1, -2 },
{ -2, -1, -1, -1, -1, -2, -2 },
{ -2, -2, -1, -1, -1, -2, -2 },
{ -2, -2, -1, -1, -1, -2, -2 },
{ -2, -2, -1, -3, -1, -2, -2 }
};
const unsigned int h = sizeof grid_array / sizeof grid_array[0];
const unsigned int w = sizeof grid_array[0] / sizeof grid_array[0][0];
GL_BaseCamp/01-L-Introduction/main.c
Line 19 in 59705ea
Pay attention to naming scheme. The CamelCaseNames shouldn't be used unless you're declaring a class-like object. (per CodingStyle)
GL_BaseCamp/01-L-Introduction/main.c
Line 32 in 59705ea
The
void func()
means to compiler that arguments are unknown at compile-time. This could lead to weird obscure errors. It's better to explicitly use void func(void)
if function takes no arguments
GL_BaseCamp/01-L-Introduction/main.c
Line 36 in 59705ea
What happens here. You declare a 2-byte string, and it gets assigned the int 0,0 value, which essentially equals '\0', '\0'. It's better to do it explicitly and assign
symbol
an empty string. Also it exists only during the { code block } time, so it's better to reserve more space to allow for any int to fit, i.e. size = 1 + int(floor(log10(INT_MAX)));
GL_BaseCamp/01-L-Introduction/main.c
Line 61 in 59705ea
The person reading your code should keep in memory the whole operator precedence table. To avoid this, better explicitly place () braces.
GL_BaseCamp/01-L-Introduction/main.c
Line 73 in 59705ea
Better to assign directly to array and avoid using pointer here
GL_BaseCamp/01-L-Introduction/main.c
Lines 102 to 103 in 59705ea
CodingStyle says it should be done like shown below
} else if (*west == -1) {
GL_BaseCamp/01-L-Introduction/main.c
Lines 119 to 124 in 59705ea
McCabe complicity too high here
GL_BaseCamp/01-L-Introduction/main.c
Line 137 in 59705ea
Error here: timespecs get created, but not filled with
clock_gettime()
value. It results in difference of junk being calculated by diff instead of time. (malloc
in contrast to calloc
does not clear the allocated memory)
GL_BaseCamp/02-P-Dev_Tools
GL_BaseCamp/02-P-Dev_Tools/Makefile
Lines 18 to 19 in 59705ea
This stuff is not required. The
$(TARGET)
should depend on $(TARGET:=.c)
file and that's all what needed. Take a look at this Makefile, its representative of a yet simple but good approach:
TARGET=imfilter
DEPS=libimf
LIBS=
CC=gcc
CFLAGS=-O2 -Wall -Wextra -Wpedantic -Werror
LIBFLAGS:=-lm
ifneq ("$(LIBS), "")
LIBFLAGS+=$(shell pkg-config --cflags --libs $(LIBS) | sed -e 's/^[[:space:]]*//')
endif
DEPS:=$(addsuffix .o, $(DEPS))
.PHONY: help all clean
help: ## display this message
@echo Available options:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
all: clean | $(TARGET) ## clean & build all
$(TARGET): $(DEPS) ## build target executable
$(CC) $(CFLAGS) $(LIBFLAGS) $(addsuffix .c, $(TARGET)) -c
$(CC) $(CFLAGS) $(LIBFLAGS) $(DEPS) $(addsuffix .o, $(TARGET)) -o $@
%.o: %.c
$(CC) $(CFLAGS) $(LIBFLAGS) -c $<
clean: ## tidy build directory
@echo Cleaning up...
-rm -f $(DEPS) $(TARGET) $(addsuffix .o, $(TARGET))
Wow, visual representation is beautiful!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.