Giter Club home page Giter Club logo

c-labs's Introduction

C Labs

Experiments and short programs written in C.

Requirements

  1. Docker or
  2. Your preferred way of compiling C (e.g GCC).

Setup with Docker

The following command will build an image that can compile and run C programs, will bind this project folder to the container's /home/source/ and it will keep the container alive indefinetly so that the project can be worked on.

docker compose up --detach

Then access the container using the ID if known or the name which will always be clang:

docker exec -it clang /bin/bash

With access to the container switch the directory to find the project files e.g:

cd /home/source/hello

Compile programs and run binaries as needed:

# Compile the program:
gcc -o main ./main.c

# or with clang:
clang -g -Wall -std=c99 -o main ./main.c

# Run the program:
./main

The command can also be combined so that it tries to run after it is compiled:

clang -g -Wall -std=c99 -o main ./main.c && ./main

When done, exit the interactive terminal with Ctrl+C and remove the containers or type exit:

docker compose down

Programs can also be inspected for memory leaks using valgrind <file>:

root@567cbfe975b0:/home/project/source/malloc# valgrind ./main

==40== Memcheck, a memory error detector
==40== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==40== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==40== Command: ./main
==40==
source: hello
target: Hello
==40==
==40== HEAP SUMMARY:
==40==     in use at exit: 0 bytes in 0 blocks
==40==   total heap usage: 2 allocs, 2 frees, 1,030 bytes allocated
==40==
==40== All heap blocks were freed -- no leaks are possible
==40==
==40== For counts of detected and suppressed errors, rerun with: -v
==40== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

The clang static analyzer can also be used with scan-build:

scan-build clang main.c

The output should look similar to the following:

root@3fc228fa345f:/home/project/source/arrays# scan-build clang main.c
scan-build: Using '/usr/lib/llvm-16/bin/clang' for static analysis
scan-build: Analysis run complete.
scan-build: Removing directory '/tmp/scan-build-2024-01-14-233048-110-1' because it contains no reports.
scan-build: No bugs found.

c-labs's People

Contributors

csalmeida avatar

Watchers

 avatar

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.