Specjalistyczny podręcznik Programowania w C

Wstęp edytuj

  1. pierwszy przykład
    1. program z SDL
    2. Więcej o kompilacja
    3. Makra preprocessora = przetwarzanie kodu źródłowego programu przed jego kompilacją

obiektowe-c edytuj

Objective-C – rozszerzenie języka C o możliwości obiektowe, wzorowane na Smalltalku. Objective-C przyjął drogę całkowicie odmienną od C++. Jest używany głównie w frameworku Cocoa w systemie OS X oraz w iOS.


kompilacja na Ubuntu [1]

Programowanie równoległe edytuj

  1. CPU
    1. MIC = CPU z wieloma rdzeniami (SIMD, OpenMP) i koprocesor Xeon Phi
    2. pthreads = wątki
    3. GNU UPC
    4. ispc - Intel SPMD Program Compiler. An open-source compiler for high-performance SIMD programming on the CPU
  2. Procesor Cell i Sony PS3
  3. GPU
    1. CUDA
    2. OpenCL
    3. Cg

Biblioteki, moduły i pakiety edytuj

Interfejs programistyczny aplikacji (ang. Application Programming Interface, API) edytuj

  1. standardowe (libc, ...)
  2. pthreads
  3. glib wykorzystywane w GTk i Gnome


Standardy edytuj

  • POSIX


Wskazówki POSIX dotyczące składni poleceń

numeryczne edytuj

  1. imath is a C++ and python library of 2D and 3D vector, matrix, and math operations for computer graphics
  2. GSL
  3. PARI (libpari)
  4. Anant -- Algorithmic 'n Analytic Number Theory by Linas Vepstas
  5. The multiple-digit approach
    1. GMP
    2. MPFR
    3. MPC
    4. Flint
    5. Arb
      1. arbcmath
  6. the multiple-component approach
    1. doubledouble by Keith Briggs
    2. quad_float in Victor Shoup's NTL library.
    3. []
    4. qd
      1. GQD = qd na GPU
  7. GPU
    1. CAMPARY = CudA Multiple Precision ARithmetic librarYMuller-Popescu-Tang presentation
  8. przenośne (ang. portable) = które nie wymagają instalacji:
    1. APR


"The multiple-digit approach can representamuch larger range of numbers, whereas the multiple-component approach has the advantage in speed."

Grafika edytuj

  1. Grafika[3][4]
    1. OpenGL oraz Glut, Glew, GLSL ....
    2. Gegl
    3. GraphicsGems - Code for the "Graphics Gems" book series
    4. Code developed for articles in the "Journal of Graphics Tools"
    5. libgd = GD Graphics (Draw) Library : sudo apt-get install libgd-dev
    6. OpenCV
    7. libpng
    8. cjpeg - CLI program, który konwertuje plik lub stdout do pliku jpg
    9. Programowanie_w_systemie_UNIX/c_grafika#Plotutils i libplot
    10. libvips
    11. openexr
    12. AOMediaCodec libavif Library for encoding and decoding .avif files ( HDR)
    13. Gdk-pixbuf Image loading library
    14. cairo, pixman
    15. Pango - is a library for laying out and rendering of text, with an emphasis on internationalization.
    16. GR is a universal framework for cross-platform visualization applications.
    17. plplot
    18. Heman is a C library of image utilities for dealing with height maps and other floating-point images.
    19. dislin s a high-level plotting library for displaying data as curves, polar plots, bar graphs, pie charts, 3D-color plots, surfaces, contours and maps.
    20. gfx a simple graphics library for X11
    21. picasso is a high quality vector graphic rendering library. It support path , matrix , gradient , pattern , image and truetype font.
    22. olive.c is a simple graphics library that does not have any dependencies and renders everything into the given memory pixel by pixel.
    23. raylib A simple and easy-to-use library to enjoy videogames programming
  2. color
    1. rgb565 colors by Nic Newdigate
  3. GUI
    1. SDL
    2. gtk
    3. Glut
    4. IUP = Portable User Interface
    5. SFML = Simple and Fast Multimedia Library
    6. Nuklear - 1 file
    7. cefapi A simple example on how to use the C API in Chromium Embedded Framework created by Czarek Tomczak.
    8. Sokol: Simple STB-style cross-platform libraries for C and C++, written in C by Andre Weissflog ( floooh )
    9. Sokol GP. Minimal efficient cross platform 2D graphics painter in pure C using modern graphics API through the excellent Sokol GFX library. Sokol GP, or in short SGP, stands for Sokol Graphics Painter by Eduardo Bart edubart
    10. lcui
    11. webview
    12. raygui A simple and easy-to-use immediate-mode gui library


Wczytywanie obrazu z użyciem stb_image[5]

 

#include <stdint.h>

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

int main() {
    int width, height, bpp;

    uint8_t* rgb_image = stbi_load("image.png", &width, &height, &bpp, 3);

    stbi_image_free(rgb_image);

    return 0;
}

Tworzenie obrazu z użyciem stb_image

 
#include <stdint.h>

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

#define CHANNEL_NUM 3

int main() {
    int width = 800; 
    int height = 800;

    uint8_t* rgb_image;
    rgb_image = malloc(width*height*CHANNEL_NUM);

    // Write your code to populate rgb_image here

    stbi_write_png("image.png", width, height, CHANNEL_NUM, rgb_image, width*CHANNEL_NUM);

    return 0;
}


 
Schema of the layers of the graphical user interface ( GUI)

dźwięk edytuj

 
#include <soundio/soundio.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

static const float PI = 3.1415926535f;
static float seconds_offset = 0.0f;
static void write_callback(struct SoundIoOutStream *outstream,
        int frame_count_min, int frame_count_max)
{
    const struct SoundIoChannelLayout *layout = &outstream->layout;
    float float_sample_rate = outstream->sample_rate;
    float seconds_per_frame = 1.0f / float_sample_rate;
    struct SoundIoChannelArea *areas;
    int frames_left = frame_count_max;
    int err;

    while (frames_left > 0) {
        int frame_count = frames_left;

        if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
            fprintf(stderr, "%s\n", soundio_strerror(err));
            exit(1);
        }

        if (!frame_count)
            break;

        float pitch = 440.0f;
        float radians_per_second = pitch * 2.0f * PI;
        for (int frame = 0; frame < frame_count; frame += 1) {
            float sample = sin((seconds_offset + frame * seconds_per_frame) * radians_per_second);
            for (int channel = 0; channel < layout->channel_count; channel += 1) {
                float *ptr = (float*)(areas[channel].ptr + areas[channel].step * frame);
                *ptr = sample;
            }
        }
        seconds_offset = fmod(seconds_offset + seconds_per_frame * frame_count, 1.0);

        if ((err = soundio_outstream_end_write(outstream))) {
            fprintf(stderr, "%s\n", soundio_strerror(err));
            exit(1);
        }

        frames_left -= frame_count;
    }
}

int main(int argc, char **argv) {
    int err;
    struct SoundIo *soundio = soundio_create();
    if (!soundio) {
        fprintf(stderr, "out of memory\n");
        return 1;
    }

    if ((err = soundio_connect(soundio))) {
        fprintf(stderr, "error connecting: %s\n", soundio_strerror(err));
        return 1;
    }

    soundio_flush_events(soundio);

    int default_out_device_index = soundio_default_output_device_index(soundio);
    if (default_out_device_index < 0) {
        fprintf(stderr, "no output device found\n");
        return 1;
    }

    struct SoundIoDevice *device = soundio_get_output_device(soundio, default_out_device_index);
    if (!device) {
        fprintf(stderr, "out of memory\n");
        return 1;
    }

    fprintf(stderr, "Output device: %s\n", device->name);

    struct SoundIoOutStream *outstream = soundio_outstream_create(device);
    if (!outstream) {
        fprintf(stderr, "out of memory\n");
        return 1;
    }
    outstream->format = SoundIoFormatFloat32NE;
    outstream->write_callback = write_callback;

    if ((err = soundio_outstream_open(outstream))) {
        fprintf(stderr, "unable to open device: %s", soundio_strerror(err));
        return 1;
    }

    if (outstream->layout_error)
        fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error));

    if ((err = soundio_outstream_start(outstream))) {
        fprintf(stderr, "unable to start device: %s\n", soundio_strerror(err));
        return 1;
    }

    for (;;)
        soundio_wait_events(soundio);

    soundio_outstream_destroy(outstream);
    soundio_device_unref(device);
    soundio_destroy(soundio);
    return 0;
}

Debugowanie edytuj

  1. gdb
  2. backtrace
    1. libc backtrace [6]
    2. libunwind[7]
    3. Postmortem Debugging [8]
    4. nanolat [9]
    5. stck trace [10]
    6. Stack unwinding (stack trace) with GCC[11]

Dodatkowe materiały edytuj

Źródła edytuj

  1. stackoverflow :compiling-objective-c-on-ubuntu-using-gcc
  2. askubuntu question: difference-between-libasan-packes-libasan0-libasan2-libasan3-etc
  3. stackoverflow question: graphics-library-in-c
  4. moderncprogramming: how-can-you-draw-shapes-in-c-easily
  5. stackoverflow question: reading-an-image-file-in-c
  6. libc backtrace
  7. libunwind
  8. Postmortem Debugging by Stefan Wörthmüller
  9. nanolat by Kangmo Kim
  10. Catching Exceptions and Printing Stack Traces for C on Windows, Linux, & Mac BY: JOB VRANISH
  11. Stack unwinding (stack trace) with GCC
  12. Programowanie w języku C - Artur Pyszczuk