Coder Social home page Coder Social logo

gl_basecamp's People

Contributors

buinich-bohdan avatar

Watchers

James Cloos avatar

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

#define WIDTH 9
#define HEIGHT 7
int gridArray[WIDTH][HEIGHT] = {

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];

int gridArray[WIDTH][HEIGHT] = {

Pay attention to naming scheme. The CamelCaseNames shouldn't be used unless you're declaring a class-like object. (per CodingStyle)

void DrawGrid()

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

char symbol[2] = {};

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)));

for (int x = 0; x < WIDTH && !foundEnd; ++x) {

The person reading your code should keep in memory the whole operator precedence table. To avoid this, better explicitly place () braces.

int* north = &(gridArray[x][y + 1]); //ptr to grid

Better to assign directly to array and avoid using pointer here

}
else if (*west == -1) {

CodingStyle says it should be done like shown below

 } else if (*west == -1) {

}
}
}
}
}
}

McCabe complicity too high here

struct timespec time_now, time_after;

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

main.o: main.c
gcc -c -o $(DEPS) $(SRC)

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))

img

Wow, visual representation is beautiful!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.