Programming is in a sense easy. But mistakes are what always cause more problems. Can someone help me with some good debugging tricks and tools in c?
Popular debugging tools are listed below.
Some very simple tricks / suggestions
-> Always check that nowhere in your code have you dereferenced a wild / sagging pointer
Example 1)
int main() { int *p; *p=10; //Undefined Behaviour (crash on most implementations) }
Example 2)
int main() { int *p=malloc(sizeof(int)); //do something with p free p; printf("%d", *p); ////Undefined Behaviour (crash on most implementations) }
-> Always initialize variables before use
int main() { int k; for(int i= k;i<10;++i) ^^ Ouch printf("%d",i"); }
From "Elements of a Programming Style," Brian Kernigan, 2nd Edition, Chapter 2:
, . , , , , - ?
, ; " "!
, ; ! . , , , .
, ; . , lint, pclint QA-C, .
, . , , - , . :
, , , , , !
C
:
. .
-
(gdb, valgrind, ), .
size_t
ptrdiff_t
off_t
enum
int
long
char
uint8_t
int8_t
double
struct
NULL
assert
, .
, David Agans. .
valgrind , Linux. gdb/ddd linux. , , windbg. , , gdb; , . assert, , , . , Check, cunit .. NULL, . , NULL. segfault, . , . , , 10 , . gcc -Wall -Wextra. strn * str *. , .
Source: https://habr.com/ru/post/1754763/More articles:PHP Checksum before include () - securityhow to make drupal submit form using ajax? - jqueryFlex AdvancedDataGrid sort - sortingfinding an easy way to change multiple tables at once in mysql - mysqlWhy is the tar command marked as "legacy"? - shellhow to use Linq to generate a unique random number - linqwhat is the difference between short signed ints and signed ints - cJava: distribution of power law - javaВызовите функцию плагина smarty непосредственно из PHP - phpКак уникально диктовать по значению? - pythonAll Articles