about summary refs log tree commit diff stats
path: root/sandbox/008-sandbox-edit.mu
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/008-sandbox-edit.mu')
0 files changed, 0 insertions, 0 deletions
9' href='#n89'>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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
	<meta charset='utf-8'>
	<title>C &amp; GDB</title>
    </head>
    <body>
        <a href="index.html">C Index</a>

	<h1>Hello World</h1>

        <p>C "allows to implement" or approach to various
        programming paradigms but due to it's characteristics
        it's more a procedural language. C procedural programs
        are divided in smaller procedures, or functions, and
        data or pointers to data are passed into them or is
        shared between them. To get started create file
        hello.c with;</p>

	<pre>
	#include &lt;stdio.h&gt;

	int main() {
	    printf("Hello World!");
	    return 0;
	}
	</pre>

	<p>Compile;</p>

	<pre>
	$ gcc -Wall hello.c -o hello
	</pre>

	<p>Run;</p>

	<pre>
	$./hello
	Hello World!
	</pre>

	<h2 id="makefile">Makefile</h2>

	<p>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.<p>

	<p>Create Makefile;</p>

	<pre>
	CC=gcc
	CFLAGS=-Wall

	hello: main.o hello.o

	clean:
		rm -f hello main.o hello.o
	</pre>

	<pre>
	$ touch NEWS README AUTHORS ChangeLog
	</pre>

	<h2 id="debug">Debug</h2>

	<p>To use gdb you need to compile program with -g flag. Change
	Makefile</p>

	<pre>
	CC=gcc
	CFLAGS=-Wall -g

	hello: main.o hello.o

	clean:
		rm -f hello main.o hello.o
	</pre>

	<pre>
	$ gdb hello
	</pre>

	<p>Set break point;</p>

	<pre>
	(gdb) break main
	</pre>

	<p>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;</p>

	<pre>
	(gdb) run
	</pre>

	<p>Step in next line;</p>

	<pre>
	(gdb) s
	</pre>

        <p>Print variable "name" value;</p>

        <pre>
        (gdb) print name
        $1 = 0x4005b0 "world"
        (gdb)
        </pre>

        <p>Print variable "name" type;</p>

        <pre>
        (gdb) ptype name
        type = const char *
        (gdb)
        </pre>

        <p>Variable is a <a href="elements.html#const">string constant</a>.
        Execute next line to end;</p>

	<pre>
	(gdb) n
	</pre>

        <a href="index.html">C Index</a>
	<p>
	This is part of the Hive System Documentation.
	Copyright (C) 2019
	Hive Team.
	See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
	for copying conditions.</p>
    </body>
</html>