Git Product home page Git Product logo

liblcthw's Introduction

LibLCTHW

This is the library that you finally create in my book Learn C The Hard Way found at:

http://c.learncodethehardway.org/

This code is usually in sync with the book, but sometimes it gets out of sync during editing sessions. If you find a difference or a bug, just submit your pull request and I'll take a look.

liblcthw's People

Contributors

bostjan avatar constfun avatar danim avatar multivac61 avatar zedshaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

liblcthw's Issues

ringbuffer.c - improper use of memcpy return value

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

suspect check in ringbuffer.c

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

RingBuffer isn't really a ring buffer

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 for List_clear_destroy()

The Problem

Missing a test to check if the code actually worked or not.

char *test_destroy()
{
List_clear_destroy(list);
return NULL;
}

My Approach

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.

image

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

Suggested Solution

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.

mergesort and heapsort not found when linking under Ubuntu

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.

I am sorry

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.

Doesn't compile anymore โ€“ CLANG error

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

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.