58
There is more to C 26.11. 2012 FI MUNI Juraj Michálek http://georgik.sinusgear.com http://twitter.com/sinusgear

There is more to C

Embed Size (px)

DESCRIPTION

Slides form talk at FI MUNI about development in C (2012). Covers topic about C libraries including libuv library from Node.js and its relation to Google V8 JavaScript Engine.

Citation preview

Page 1: There is more to C

There is more to C

26.11. 2012FI MUNI

Juraj Michálekhttp://georgik.sinusgear.comhttp://twitter.com/sinusgear

Page 2: There is more to C

Something about me ;-)

Page 3: There is more to C

Content

Why C rocks?

libuv

Page 4: There is more to C

#1 language 2012

http://www.tiobe.com

Page 5: There is more to C

Trends

Page 6: There is more to C

Interactive C - Robot

● Handyboard● Motorola 68AX11● derrived from C● http://www.kipr.org● http://www.boatball.org

Page 7: There is more to C

Portability

Linux – Windows – Mac – BSD

http://suacommunity.com/

Page 8: There is more to C

Clone examples

Available at GitHub:https://github.com/georgik/fimuni-c-cpp-examples

git clone git://github.com/georgik/fimuni-c-cpp-examples.git

Page 9: There is more to C

Allegro

Allegro Low Level Game Routines

Page 10: There is more to C

Allegro - features

keyboard, mouse, touch screenaudio, video, graphics

timers, eventsdata files

Page 11: There is more to C

Allegro 5.1

Win, Lin, Mac

iOS, Android

http://alleg.sourceforge.net/a5docs/refman/

Page 12: There is more to C

Initialization

al_init();

Page 13: There is more to C

Graphic environment

al_create_display(int w, int h)

Page 14: There is more to C

ALLEGRO_BITMAP

Structure for bitmaps

ALLEGRO_BITMAP *bmp = create_bitmap(x,y);

Page 15: There is more to C

Graphics

al_putpixel(x, y, color)

al_load_bitmap(filename);

al_draw_bitmap(bmp, 10, 10, 0);

Page 16: There is more to C

Release memory

al_destroy_bitmap(bmp);

Page 17: There is more to C

Keyboard

al_install_keyboard()al_uninstall_keyboard()

event.keyboard.keycode

Page 18: There is more to C

Mouse

al_install_mouse()al_uninstall_mouse()

al_get_mouse_state(&msestate);

Page 19: There is more to C

Additional Allegro libraries

Allegttf - True Type fonts support

AllegGL – HW accelerated graphics

DUMB - audio (Vorbis/Ogg)

Page 20: There is more to C

CompilationConfiguration script:allegro-config

Linux, Unix, MacOS:gcc foo.cc -o foo `allegro-config --libs`

gcc foo.cc -o foo `pkg-config --libs --cflags allegro-5.0`

iPhone – requires Xcode

Android – requires Android SDK

Page 21: There is more to C

CMake – Cross Platform Make

http://www.cmake.org

Page 22: There is more to C

Allegro – CMake – MSVC 2012

Requires: DirectX SDK (e.g. Windows SDK for Windows 8)Small tweak to run examples: http://georgik.sinusgear.com/2012/11/18/allegro5-1-and-visual-studio-2012-unable-to-start-examples-missing-dll-files/

Page 23: There is more to C

Allegro – CMake - KDevelop4

Page 24: There is more to C

Sources

Library: http://alleg.sourceforge.net

Wiki: http://wiki.allegro.cc/

Page 25: There is more to C

Game development community network

http://www.allegro.cc

Page 26: There is more to C

Simple Direct Media Layer

Page 27: There is more to C

Init/quit

SDL_init(flags)

SDL_quit()

Page 28: There is more to C

Graphics

SDL_SetVideoMode(width, height, video_bpp, videoflags)

Store in memory: SDL_SWSURFACEStore on graphics card: SDL_HWSURFACE

Page 29: There is more to C

Visual data

SDL_Surface

SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, gmask, bmask,

amask);

Page 30: There is more to C

Visual data

SDL_Surface *SDL_LoadBMP(const char *file)

Copy from one memory to another:SDL_BlitSurface(src, srcrect, dst,

dstrect);

Page 31: There is more to C

Keyboard

SDL_PollEvent(SDL_Event *event)

event.key.keysym.sym

Page 32: There is more to C

Timer

static int counter;

SDL_SetTimer(interval, tick_callback);

Page 33: There is more to C

Mouse

SDL_GetMouseState(*x, *y);

Page 34: There is more to C

Text

Not implemented

Page 35: There is more to C

Extensions

support for GL

extension for many languagesAda, Eiffel, Java, Lua, Perl, PHP, Pike, Python,

Ruby

176 additional libraries

Page 36: There is more to C

SDL based Libraries

SDL_mixer – audio mixer

SDL_image – image formats

SDL_net – network support

Page 37: There is more to C

Source

http://www.libsdl.org

Page 38: There is more to C

Compilation

sdl-config

Linux, Windows, BeOS, Mac OSgcc foo.cc -o foo `sdl-config --libs`

Page 39: There is more to C

PyGame

Power of C and Power of Pythonhttp://www.pygame.org

Page 40: There is more to C

http://nodejs.org/

Page 41: There is more to C

Architecture of Node.js

Page 42: There is more to C

libuv

High performance evented I/O library

which offers the same API

on Windows and Unix

Page 43: There is more to C

libuv

https://github.com/joyent/libuv

http://nikhilm.github.com/uvbook/index.html

Page 44: There is more to C

libuv – event loop

Call callbacks Sleep

Page 45: There is more to C

libuv - example

Page 46: There is more to C

Features

Filesystem

Networking

Threads

Processes

Utilities

Page 47: There is more to C

TCP server example

Page 48: There is more to C

http://www.gtk.org

Page 49: There is more to C

GTK

GIMP ToolKit

C++, Guile, Perl, Python, TOM, Ada95, Objective C, Free Pascal, Eiffel...

Page 50: There is more to C

Glade 3

http://glade.gnome.org

Page 51: There is more to C

Valgrind

debugging a profiling

memcheck

helgrind - race condition, thread profiling

Page 52: There is more to C

Modes debugger

Local application

Attach to local process

Attach to remote process

Post-mortem

Page 53: There is more to C

Application crashed

Post-mortem analysis

Image from memory: coredump

Page 54: There is more to C

Quick analysis of coredump

Page 55: There is more to C

Strace

Page 56: There is more to C

Mutextrace

● mutextrace ./mutex-tester-app param1 param2– lock #1, free -> thread 1

– init #2

– lock #2, free -> thread 1

– unlock #1

– lock #1, free -> thread 1

– init #3

– lock #3, free -> thread 1

– unlock #1

Page 57: There is more to C

http://www.se-radio.net

Page 58: There is more to C

EOF

26.11. 2012FI MUNI

Juraj Michálekhttp://georgik.sinusgear.comhttp://twitter.com/sinusgear