From 7d97b6843255520e708cbd48497fd04992d2c183 Mon Sep 17 00:00:00 2001 From: Silvino Date: Mon, 29 Jul 2019 18:43:41 +0100 Subject: fix dev c index --- dev/c/index.html | 152 ------------------------------------------------------- 1 file changed, 152 deletions(-) diff --git a/dev/c/index.html b/dev/c/index.html index 0e54a13..72ea270 100644 --- a/dev/c/index.html +++ b/dev/c/index.html @@ -78,158 +78,6 @@
  • Autotools
  • - -

    C & GDB

    - -

    Hello World

    - -

    Create file hello.c with;

    - -
    -	#include <stdio.h>
    -
    -	int main() {
    -	    printf("Hello World!");
    -	    return 0;
    -	}
    -	
    - -

    Compile;

    - -
    -	$ gcc -Wall hello.c -o hello
    -	
    - -

    Run;

    - -
    -	$./hello
    -	Hello World!
    -	
    - -

    Multiple Sources

    - -

    To organize code in multiple files split above - example in main.c, hello.c and hello.h. Content of - main.c;

    - -

    -	#include "hello.h"
    -
    -	int main() {
    -	    hello("world");
    -	    return 0;
    -	}
    -	
    - -

    Header file contains declaration of the function hello, - content of hello.h;

    - -
    -	void hello(const char* name);
    -	
    - -

    Implementation of hello function in hello.c;

    - -
    -	#include <stdio.h>
    -	#include "hello.h"
    -
    -	void hello(const char* name) {
    -	    printf("Hello, %s!\n", name);
    -	}
    -	
    - -

    Compile;

    - -
    -	$ gcc -Wall main.c hello.c -o hello
    -	
    - -

    Makefile

    - -

    Make reads a Makefile by default on current directory, - Makefile defines targets, for example executables and their - dependencies, for example object files and source files.

    - -

    Create Makefile;

    - -
    -	CC=gcc
    -	CFLAGS=-Wall
    -
    -	hello: main.o hello.o
    -
    -	clean:
    -		rm -f hello main.o hello.o
    -	
    - -
    -	$ touch NEWS README AUTHORS ChangeLog
    -	
    - -

    Debug

    - -

    To use gdb you need to compile program with -g flag. Change - Makefile

    - -
    -	CC=gcc
    -	CFLAGS=-Wall -g
    -
    -	hello: main.o hello.o
    -
    -	clean:
    -		rm -f hello main.o hello.o
    -	
    - -
    -	$ gdb hello
    -	
    - -

    Set break point;

    - -
    -	(gdb) break main
    -	
    - -

    To start the program you can type run, this way gdb - will try to run the program until the end. If program - crash, gdb will stop it for debuging. Start program;

    - -
    -	(gdb) run
    -	
    - -

    Step in next line;

    - -
    -	(gdb) s
    -	
    - -

    Print variable "name" value;

    - -
    -        (gdb) print name
    -        $1 = 0x4005b0 "world"
    -        (gdb)
    -        
    - -

    Print variable "name" type;

    - -
    -        (gdb) ptype name
    -        type = const char *
    -        (gdb)
    -        
    - -

    Variable is a string constant. - Execute next line to end;

    - -
    -	(gdb) n
    -	
    - Development Index

    This is part of the Hive System Documentation. -- cgit 1.4.1-2-gfad0 href='#n10'>10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113