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 $ gcc -o associtivity_in_c associtivity_in_c.c $ ./associtivity_in_c This program will display result as 5. Associativity of … Read more

How to execute C code from go – c to golang binding

package main // If a Go source file imports “C”, it is using cgo. The Go file will have access to anything appearing in the comment immediately preceding the line import “C”, and will be linked against all other cgo comments in other Go files, and all C files included in the build process. /* … Read more

How to resolve error : ” no buildable Go source files in “

Sometimes when we try to compile an unknown go package, we can see an error like “no buildable Go source files in”, the possible solution could be, Check if the package which shows error “no buildable Go source files in” is using C code, like import “C” in the source file, in that case, we … 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 Now, we will need to install electric-fence package on ubuntu as, $ sudo apt-get install electric-fence Reading package lists… Done Building dependency tree Reading state information… Done The following NEW packages will be … 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 Compile above source as, $ gcc -o str_to_file str_to_file.c Test / Execute it as, $ ./str_to_file This will create myfile.txt in your current working directory where you have str_to_file binary, The code is also available at github