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!
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
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) nC Index
This is part of the Tribu System Documentation. Copyright (C) 2020 Tribu Team. See the file Gnu Free Documentation License for copying conditions.