diff options
author | Silvino <silvino@bk.ru> | 2019-07-29 18:54:28 +0100 |
---|---|---|
committer | Silvino <silvino@bk.ru> | 2019-07-29 18:54:28 +0100 |
commit | 52f8e253736be4d3f9c8dac778cc5e4c5ddc85a8 (patch) | |
tree | 9e9a1e6f6775e69361d871706ee12f6e4b6f9d8f | |
parent | 1e6c3b6fe37b10c0844c10860684f5434c74cf90 (diff) | |
parent | 7d97b6843255520e708cbd48497fd04992d2c183 (diff) | |
download | doc-52f8e253736be4d3f9c8dac778cc5e4c5ddc85a8.tar.gz |
Merge branch 'master' into develop
-rw-r--r-- | dev/c/index.html | 152 |
1 files changed, 0 insertions, 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 @@ <li><a href="http://inti.sourceforge.net/tutorial/libinti/autotoolsproject.html">Autotools</a></li> </ul> - - <h1>C & GDB</h1> - - <h2 id="hello">Hello World</h2> - - <p>Create file hello.c with;</p> - - <pre> - #include <stdio.h> - - 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 ="sources">Multiple Sources</h2> - - <p>To organize code in multiple files split above - example in main.c, hello.c and hello.h. Content of - main.c;<p> - - <pre> - #include "hello.h" - - int main() { - hello("world"); - return 0; - } - </pre> - - <p>Header file contains declaration of the function hello, - content of hello.h;</p> - - <pre> - void hello(const char* name); - </pre> - - <p>Implementation of hello function in hello.c;</p> - - <pre> - #include <stdio.h> - #include "hello.h" - - void hello(const char* name) { - printf("Hello, %s!\n", name); - } - </pre> - - <p>Compile;</p> - - <pre> - $ gcc -Wall main.c hello.c -o hello - </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">Development Index</a> <p> This is part of the Hive System Documentation. |