Solved: compilation error for ARM toolchain “undefined reference to `_exit'”

Our ARM toolchain was extracted at “/home/devlab/Desktop/helloworld/assembly/gcc-arm-none-eabi-10-2020-q4-major/” hence lets first try to add this toolchain to terminal path as, Now, we had written simple helloworld.c program, which we tried to compile as, But we got the compilation error as, Solution This error can be solved by adding “–specs=nosys.specs” at the end of the command as, … Read more

Using GDB to debug functions defined in another file in C

In our previous post “How to use gdb for debugging application programs ( On Ubuntu Linux using C program )” we seen how we can debug the C program where all of the code is written in single C file. In this post, we will show you how you can debug the C function written … Read more

Using Decision Making Statements, if and if-else in C program

When you are writing C program, sometimes you need to make certain checks on variables and based on which you need to take some decisions.. this is called as Decision making statements in C programming Language. In this post, we will show you how you can use simple conditional statements “if” and “if-else” in your … Read more

Associativity of Operators in C Programming

When some expression in C contains two operators with same/equal priority, the expression gets executed as per the “Associativity of Operators”, Check below program to understand, why it prints the results as “5” and not “1” $ vim associtivity_in_c.c [c] #include <stdio.h> int main(){ int a = 3/2*5; printf("a=%d\n", a); /*Above Statement will print result … Read more

Understanding gcc compilation steps : Linux compilation steps

Copy paste the below shell script and execute on your terminal. $ vim understanding_compilation_with_gcc.sh Copy below highlighted code and run the script as, $ bash understanding_compilation_with_gcc.sh ————- code start ——————— #!/bin/bash echo “ For any given input file, the file name suffix determines what kind of compilation is done: file.c C source code that must … Read more

Detect memory leaks using Valgrind in Linux

Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools. We will need to install valgrind for ubuntu, $ sudo apt-get install valgrind Reading package lists… … Read more

Using electric fence for debugging memory leaks in Linux

Create a test program which has some memory leaks for understanding how to debug memory leaks with electric fence, $ vim efence.c [c] #include <stdio.h> #include <stdlib.h> int main() { char *ptr = (char *) malloc(1024); ptr[0] = 0; /* Now write beyond the block */ ptr[1024] = 0; exit(0); } [/c] Now, we will … Read more

c program for creating a text file from string in buffer

Create a str_to_file.c file as contents below, OR use from github [c] #include <stdio.h> #include <stdlib.h> #include <string.h> int main (int argc, char **argv) { char *str = (char *) malloc(4096); FILE *fp; int ret; size_t size; strcpy(str, "{\"myname\":"); strcat(str, "\""); strcat(str, "devbee"); strcat(str, "\"}"); fp = fopen( "myfile.txt" , "w" ); size = fwrite(str … Read more