From 2830b5fb96cce787ca8c7562a968effc3e57bdb1 Mon Sep 17 00:00:00 2001 From: Silvino Date: Wed, 26 Jun 2019 16:58:13 +0100 Subject: dev index re-organization --- dev/c/basic.html | 59 ++++++++++++++++++++ dev/c/datatypes.html | 17 +++--- dev/c/hello.html | 134 ++++++++++++++++++++++++++++++++++++++++++++++ dev/c/index.html | 72 +++++++++++++++++++++++++ dev/c/lib.html | 8 +-- dev/c/src/basic/AUTHORS | 1 + dev/c/src/basic/ChangeLog | 0 dev/c/src/basic/Makefile | 7 +++ dev/c/src/basic/NEWS | 0 dev/c/src/basic/README | 0 dev/c/src/basic/basic.c | 3 ++ dev/c/src/basic/basic.h | 27 ++++++++++ dev/c/src/hello/Makefile | 7 +++ dev/c/src/hello/hello.c | 6 +++ 14 files changed, 331 insertions(+), 10 deletions(-) create mode 100644 dev/c/basic.html create mode 100644 dev/c/hello.html create mode 100644 dev/c/src/basic/AUTHORS create mode 100644 dev/c/src/basic/ChangeLog create mode 100644 dev/c/src/basic/Makefile create mode 100644 dev/c/src/basic/NEWS create mode 100644 dev/c/src/basic/README create mode 100644 dev/c/src/basic/basic.c create mode 100644 dev/c/src/basic/basic.h create mode 100644 dev/c/src/hello/Makefile create mode 100644 dev/c/src/hello/hello.c (limited to 'dev/c') 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 @@ + + + + + C - Basic + + + C & GDB Index + +

C - Basic

+ +

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
+	
+ + C & GDB Index +

+ This is part of the Hive System Documentation. + Copyright (C) 2019 + Hive Team. + See the file Gnu Free Documentation License + for copying conditions.

+ + 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 @@
char
-
Integer, one byte.
+
Integer is 1 byte.
+
int
-
Integer.
+
Integer numbers 4 bytes (short is 2 bytes and long is 4 bytes)
+
float
-
Single precision floating point.
+
Single precision floating point is 4 bytes.
+
double
-
Double precision floating point.
+
Double precision floating point is 8 bytes.
+
void
Absence of type.
-

Data types

Integer

+

Allowed types are char and int;

+
signed char
8 bit, from -128 to 127.
@@ -93,7 +98,7 @@
         struct point {
-            int x, y;
+            int x, y, z;
         } first_point;
         struct point second_point;
         
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 @@ + + + + + C & GDB + + + C & GDB Index + +

Hello World

+ +

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;

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

Compile;

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

Run;

+ +
+	$./hello
+	Hello World!
+	
+ +

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
+	
+ + C & GDB Index +

+ This is part of the Hive System Documentation. + Copyright (C) 2019 + Hive Team. + See the file Gnu Free Documentation License + for copying conditions.

+ + 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 @@ Development Index +

C & GDB

+ + + + + +

C & GDB

Hello World

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 @@ Libraries - Development Index + C & GDB Index

Libraries

@@ -13,12 +13,12 @@

Basic

-
include <unistd.h>
+
@include <unistd.h>
fork, pipe and I/O primitives (read, write, close, etc.) + primitve types like uid_t, pid_t etc
#include <stdlib.h>
-
Standard lib, contains primitves for number conversion +
Standard lib, contains primitives for number conversion and memory allocation
#include <stdio.h>
Basic i/o lib: printf etc
@@ -243,7 +243,7 @@ void pthread_exit(void *value_ptr); - Development Index + C & GDB Index

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 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 diff --git a/dev/c/src/basic/README b/dev/c/src/basic/README new file mode 100644 index 0000000..e69de29 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 + +int main() { + printf("hello World!"); + return 0; +} -- cgit 1.4.1-2-gfad0