diff options
Diffstat (limited to 'dev/c')
-rw-r--r-- | dev/c/basic.html | 59 | ||||
-rw-r--r-- | dev/c/datatypes.html | 17 | ||||
-rw-r--r-- | dev/c/hello.html | 134 | ||||
-rw-r--r-- | dev/c/index.html | 72 | ||||
-rw-r--r-- | dev/c/lib.html | 8 | ||||
-rw-r--r-- | dev/c/src/basic/AUTHORS | 1 | ||||
-rw-r--r-- | dev/c/src/basic/ChangeLog | 0 | ||||
-rw-r--r-- | dev/c/src/basic/Makefile | 7 | ||||
-rw-r--r-- | dev/c/src/basic/NEWS | 0 | ||||
-rw-r--r-- | dev/c/src/basic/README | 0 | ||||
-rw-r--r-- | dev/c/src/basic/basic.c | 3 | ||||
-rw-r--r-- | dev/c/src/basic/basic.h | 27 | ||||
-rw-r--r-- | dev/c/src/hello/Makefile | 7 | ||||
-rw-r--r-- | dev/c/src/hello/hello.c | 6 |
14 files changed, 331 insertions, 10 deletions
diff --git a/dev/c/basic.html b/dev/c/basic.html new file mode 100644 index 0000000..104e59a --- /dev/null +++ b/dev/c/basic.html @@ -0,0 +1,59 @@ +<!DOCTYPE html> +<html dir="ltr" lang="en"> + <head> + <meta charset='utf-8'> + <title>C - Basic</title> + </head> + <body> + <a href="../index.html">C & GDB Index</a> + + <h1>C - Basic</h1> + + <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> + + <a href="../index.html">C & GDB 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> diff --git a/dev/c/datatypes.html b/dev/c/datatypes.html index cbe19a2..77b5dbb 100644 --- a/dev/c/datatypes.html +++ b/dev/c/datatypes.html @@ -13,22 +13,27 @@ <dl> <dt>char</dt> - <dd>Integer, one byte.</dd> + <dd>Integer is 1 byte.</dd> + <dt>int</dt> - <dd>Integer.</dd> + <dd>Integer numbers 4 bytes (short is 2 bytes and long is 4 bytes)</dd> + <dt>float</dt> - <dd>Single precision floating point.</dd> + <dd>Single precision floating point is 4 bytes.</dd> + <dt>double</dt> - <dd>Double precision floating point.</dd> + <dd>Double precision floating point is 8 bytes.</dd> + <dt>void</dt> <dd>Absence of type.</dd> </dl> - <h2 id="datatypes">Data types</h2> <h2 id="int">Integer</h2> + <p>Allowed <a href="elements.html#types">types</a> are char and int;</p> + <dl> <dt>signed char</dt> <dd>8 bit, from -128 to 127.</dd> @@ -93,7 +98,7 @@ <pre> struct point { - int x, y; + int x, y, z; } first_point; struct point second_point; </pre> diff --git a/dev/c/hello.html b/dev/c/hello.html new file mode 100644 index 0000000..ff31bc9 --- /dev/null +++ b/dev/c/hello.html @@ -0,0 +1,134 @@ +<!DOCTYPE html> +<html dir="ltr" lang="en"> + <head> + <meta charset='utf-8'> + <title>C & GDB</title> + </head> + <body> + <a href="../index.html">C & GDB 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 <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 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 & GDB 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> diff --git a/dev/c/index.html b/dev/c/index.html index 2f0c068..3c48776 100644 --- a/dev/c/index.html +++ b/dev/c/index.html @@ -7,6 +7,78 @@ <body> <a href="../index.html">Development Index</a> + <h1>C & GDB</h1> + + <ul> + <li><a href="hello.html">Hello World</a> + <ul> + <li><a href="hello.html#makefile">Makefile</a></li> + <li><a href="hello.html#debug">Debug</a></li> + </ul> + </li> + <li><a href="elements.html">Elements</a> + <ul> + <li><a href="elements.html#ident">Identifiers</a></li> + <li><a href="elements.html#keywords">Keywords</a></li> + <li><a href="elements.html#const">Constants</a></li> + <li><a href="elements.html#op">Operators</a></li> + <li><a href="elements.html#sep">Separators</a></li> + <li><a href="elements.html#white">White space</a></li> + </ul> + </li> + <li><a href="datatypes.html">Datatypes</a> + <ul> + <li><a href="datatypes.html#types">Types</a></li> + <li><a href="datatypes.html#int">Integer</a></li> + <li><a href="datatypes.html#double">Real number</a></li> + <li><a href="datatypes.html#complex">Complex number</a></li> + <li><a href="datatypes.html#enum">Enumeration</a></li> + <li><a href="datatypes.html#union">Unions</a></li> + <li><a href="datatypes.html#struct">Structures</a></li> + <li><a href="datatypes.html#array">Arrays</a></li> + <li><a href="datatypes.html#pointer">Pointers</a></li> + <li><a href="datatypes.html#it">Incomplete types</a></li> + <li><a href="datatypes.html#tq">Type qualifiers</a></li> + <li><a href="datatypes.html#st">Storage class</a></li> + <li><a href="datatypes.html#format">Format type specifiers</a></li> + </ul> + </li> + + <li><a href="">Operators & Expressions</a></li> + <li><a href="">Control Flow</a></li> + <li><a href="">Functions</a></li> + <li><a href="">Input & Output</a></li> + <li><a href="basic.html">Basic</a> + <ul> + <li><a href="basic.html#sources">Multiple sources</a></li> + </ul> + </li> + <li><a href="lib.html">Libraries</a> + <ul> + <li><a href="lib.html#basic">Basic libraries</a></li> + <li><a href="lib.html#advanced">Advanced libraries</a></li> + <li><a href="lib.html#random-numbers">Random Numbers</a></li> + <li><a href="lib.html#signals">Signals</a></li> + <li><a href="lib.html#sorting">Sorting</a></li> + <li><a href="lib.html#strings">Strings</a></li> + <li><a href="lib.html#inter-process-communication">Inter Process Communication</a></li> + <li><a href="lib.html#file-io">File IO</a></li> + <li><a href="lib.html#shared-memory">Shared Memory</a></li> + <li><a href="lib.html#networking">Networking</a></li> + <li><a href="lib.html#threads">Threads</a></li> + </ul> + + + </li> + <li><a href="c/debugging.html">Debugging</a></li> + <li><a href="c/system.html">System Development</a></li> + </ul> + + <ul> + <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> diff --git a/dev/c/lib.html b/dev/c/lib.html index 4b6c07e..4531d7a 100644 --- a/dev/c/lib.html +++ b/dev/c/lib.html @@ -5,7 +5,7 @@ <title>Libraries</title> </head> <body> - <a href="../index.html">Development Index</a> + <a href="../index.html">C & GDB Index</a> <h1>Libraries</h1> @@ -13,12 +13,12 @@ <h2 id="basic">Basic</h2> <dl> - <dt>include <unistd.h></dt> + <dt>@include <unistd.h></dt> <dd>fork, pipe and I/O primitives (read, write, close, etc.) + primitve types like uid_t, pid_t etc</dd> <dt>#include <stdlib.h></dt> - <dd>Standard lib, contains primitves for number conversion + <dd>Standard lib, contains primitives for number conversion and memory allocation</dd> <dt>#include <stdio.h></dt> <dd>Basic i/o lib: printf etc</dd> @@ -243,7 +243,7 @@ void pthread_exit(void *value_ptr); </pre> - <a href="../index.html">Development Index</a> + <a href="../index.html">C & GDB Index</a> <p> This is part of the Hive System Documentation. diff --git a/dev/c/src/basic/AUTHORS b/dev/c/src/basic/AUTHORS new file mode 100644 index 0000000..dcfefd1 --- /dev/null +++ b/dev/c/src/basic/AUTHORS @@ -0,0 +1 @@ +Silvino Silva, silvino at bk dot ru diff --git a/dev/c/src/basic/ChangeLog b/dev/c/src/basic/ChangeLog new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/dev/c/src/basic/ChangeLog diff --git a/dev/c/src/basic/Makefile b/dev/c/src/basic/Makefile new file mode 100644 index 0000000..f165c15 --- /dev/null +++ b/dev/c/src/basic/Makefile @@ -0,0 +1,7 @@ +CC=gcc +CFLAGS=-Wall + +basic-c: main.o basic.o + +clean: + rm -f *.o basic-c diff --git a/dev/c/src/basic/NEWS b/dev/c/src/basic/NEWS new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/dev/c/src/basic/NEWS diff --git a/dev/c/src/basic/README b/dev/c/src/basic/README new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/dev/c/src/basic/README diff --git a/dev/c/src/basic/basic.c b/dev/c/src/basic/basic.c new file mode 100644 index 0000000..744b739 --- /dev/null +++ b/dev/c/src/basic/basic.c @@ -0,0 +1,3 @@ +#include "basic.h" + + diff --git a/dev/c/src/basic/basic.h b/dev/c/src/basic/basic.h new file mode 100644 index 0000000..6eef13f --- /dev/null +++ b/dev/c/src/basic/basic.h @@ -0,0 +1,27 @@ +enum operations{deposit, redraw} + +union u_account { + int id; + int value; + char *client_name; + int *log_head; + union u_account *next; +} + +struct s_accounts { + int total_accounts; + int total_value; + union u_account *head_account; +} + +struct s_operation { + int time, amount; + enum operations op; + struct s_operation *next; +} + +struct s_log { + int number; + struct s_operation *operation; + struct s_log *next; +} diff --git a/dev/c/src/hello/Makefile b/dev/c/src/hello/Makefile new file mode 100644 index 0000000..a6d9f07 --- /dev/null +++ b/dev/c/src/hello/Makefile @@ -0,0 +1,7 @@ +CC=gcc +CFLAGS=-Wall + +hello: hello.o + +clean: + rm -f *.o hello diff --git a/dev/c/src/hello/hello.c b/dev/c/src/hello/hello.c new file mode 100644 index 0000000..df66493 --- /dev/null +++ b/dev/c/src/hello/hello.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main() { + printf("hello World!"); + return 0; +} |