zedshaw / liblcthw Goto Github PK
View Code? Open in Web Editor NEWThe library you create when you are done with Learn C The Hard Way
Home Page: http://c.learncodethehardway.org/
License: Other
The library you create when you are done with Learn C The Hard Way
Home Page: http://c.learncodethehardway.org/
License: Other
I couldn't resist. I know that this is not the proper place. But I love you โค๏ธ .
I hug you ๐
I thank you for LCTHW
I am into it, I'll finish it. then I'll try to do great things that will never matter because - fuck the planet - we're all gonna day anyway. But I'l do great things because a kind human like you exists and pushing us a step forward to a better humanity.
https://github.com/zedshaw/liblcthw/blob/master/tests/list_algos_tests.c#L54
Here we are calling List_create
, a function that until now has taken no args, on words
, which is the list of words that we just destroyed.
Should this line be words = create_words();
?
check(result != NULL, "Failed to write data into buffer.");
Hey, looks like something has changed in OSX but neither the examples from the book (starting w/ ex32) nor the code in the git repo will compile. Error below:
Undefined symbols for architecture x86_64:
"_List_merge", referenced from:
_List_merge_sort in liblcthw.a(list_algos.o)
(maybe you meant: _List_merge_sort)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [tests/list_algos_tests] Error 1
https://github.com/zedshaw/liblcthw/blob/master/src/bstree.c#L192
I don't know if its meant to be missing the else. You should clarify by either using an else, or put the if on the next line.
When I try to compile the library under Ubuntu 17.04 I receive the following error messages:
build/liblcthw.a(darray_algos.o): In function `DArray_heapsort': liblcthw/src/lcthw/darray_algos.c:12: undefined reference to `heapsort' build/liblcthw.a(darray_algos.o): In function `DArray_mergesort': liblcthw/src/lcthw/darray_algos.c:18: undefined reference to `mergesort'
These errors appear to be related to the linker not finding heapsort and mergesort in available paths. Perhaps these sorting algorithms are not available by default.
In ringbuffer.c, and in exercise 44 of LCTHW, you have a couple instances similar to:
void *result = memcpy(buffer->buffer + buffer->end, data, length);
check(result != NULL, "Failed to write data into buffer.");
However, memcpy merely returns 'dest'. The return value is not indicative of success or failure in any way. Checking it against null is harmless but seems like a bug, and may mislead readers as to how memcpy works.
I was alerted to this issue in the comments section of a recent Hacker News post: https://news.ycombinator.com/item?id=8059283
RingBuffer_write() checks for RingBuffer_available_space() but reports RingBuffer_available_data(). Also, the request/available order does not seem to be correct:
check(length <= RingBuffer_available_space(buffer),
"Not enough space: %d request, %d available",
RingBuffer_available_data(buffer), length);
A ring buffer should write around the "edge" of the buffer. Zed's RingBuffer merely resets once it is empty.
Consider renaming to FancyBuffer or AdvancedBuffer, or change the implementation to write around the edge.
Missing a test
to check if the code actually worked or not.
Lines 18 to 24 in 1249486
Learning from p. 149 "Question Authority". ๐
Using TDD (see attached image), where I first write the test-cases first I stumbled upon a bug in the lists_tests.c
file.
The code will not really test if the list
has been cleared and destroyed.
The test will PASS
by just adding the following minimal implementation
function to list.c
void *List_clear_destroy(List *list) {
return (list);
}
I suggest adding a test using mu_assert()
, to actually test the list
variable.
Now I do not know if there is any better way to test this, but at least it is testing something. ๐
char *test_destroy()
{
List_clear_destroy(list);
// Add the following test
mu_assert(list->count == 0, "Failed to clear list");
return NULL;
}
What do you think @zedshaw ?
Do you have a better way to test and check if the list
is empty, please let me know because I am very curious about how that could be done.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.