Posts

Showing posts from August, 2020

Linking of Programs using Header

Image
                          Linking of Programs using Header  It's only takes 4 steps to link 2 programs 1) Keep the name of the header and name of the file same 2) Declare all function declarations in the name.h as defined in name.c 3) Now call the header file name.h using #include "name.h" in main.c 4) Compile both the binaries together using gcc command. It is Shows same behavior as in inheritance in C++

Vim Practical useful tips

  :g/^$/d (for removing extra empty lines) gg=G (for indentation) :se hls (to highlight an identifier) :syn off (for decreasing brightness in vi editor) :vsp <filename> for opening split window [Filename should be in current directory] :sp <filename> for opening split window horizontally [Filename should be in current directory] CTAGS usage in VIM  ------------------ For creation of tag file we need to run ctags command in linux as given below ctags --langmap=c:.c.h.x -h .h.x --tag-relative=no -VR >/dev/null & or ctags -R * :se tags=$PWD<press-tab to replace $PWD with actual present path>/tags Crtl+} braces to jump to definition Ctrl+T to jump back  Shift/Crtl + 5 for toggling(jumping) to end of the block(from '{' to '}') vim -t <funcname> (to jump to function defination after creation of tag file) :100 (to jump to line number 100 in a text file) :$ (to jump to end of the file) 44yy (for copying 44 lines) p (to paste code from yy command...

Optimization of C/C++ Program

                                 Optimization of C/C++ Program  gcc -O3 <c-filename.c> #pragma GCC optimize("O3")  or #pragma GCC optimize("Ofast")    #pragma GCC target("avx,avx2,fma") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #pragma GCC optimization ("unroll-loops") #pragma GCC optimization ("omit-frame-pointer") inline functions for small functions Always use Assembly based library instead of writing algo from scratch or Open-source library Example:- For AES Algo we have AES Assembly instructions that is the best optimization https://en.wikipedia.org/wiki/AES_instruction_set use your own designed library function or else use C++ library functions i.e. std::memcpy as they are better than C counter part. process affinity/core binding zero-copy mechanism to pass buffer used Sha...

List of Projects Idle for C/C++

 C Preprocessor  B Compiler(B Programming Language)  Small subset of C Compiler having RISC-V/ARM specific instruction emitting out Debugger JavaScript/HTML framework like Svelte or UI scripted language to generate a native GUI like Qt as output Windows installer using C or Julia BuildSystem like CMake in Julia LINPACK, BLAS , POSIX, CLayout library binding for Julia using C Interfacing  REST API like https://github.com/PedroFnseca/rest-api-C Abstractor utility - it will be used to remove function prototypes in header if not used,  define func prototypes in header which are used in other files, non-used will be removed from header C++ convertor to C AI OS, a UI windows designed as terminal, which takes input and output using DeepSeek and also commands like Pick OS MSI Windows Installer(.msi) C-Book dictionary, a GUI based dictionary on C Programming language File explorer Notepad++ for linux Assembler Linker and Loader Chatbot lexer and yacc Onscreen-Keyboa...

How to get symbol table in gcc/g++ ?

Image
                               How to get symbol table in gcc/g++ ?  I have a program in C++ (virt.cpp)   Now i will compile the program using maptable options which will generate a file named "mapfile" in current directory g++ -Wl,-Map -Wl,mapfile -Wl,--cref virt.cpp Now open the "mapfile" You will see the Symbols i.e. Class Names, Variables and function names(B::bar(),B::qux()) etc.

Creating a State Machine in C++ using virtual function

                                      Creating a State Machine in C++ using virtual function  We can create a state machine using virtual function , instead of normal pointer function which is using index to jump to a function, we are using Object of that particular class(which represent state) to jump to the particular run() function of that class. Here signal maps to the class object and triggers run() function of that class object. We are using concept of Runtime Polymorphism instead of compile time polymorphism. class StateMachine { // int currentState; // to store the current state public:     int signal;     void print ()     { cout<< "print base class" <<endl; }        virtual void run ()     { cou...

Memory corruption issue

                            Memory corruption issue For removing corruption we have the following guidelines as per follows:-   1) Dangling pointer- if an alias pointer(copy of another pointer) is not set to NULL after Free (pointer is given in allocation history)     2) Check memcpy/memset on a pointer which is already freed.   3) Check the size of allocation in both allocation and free call.   4) Wrong pointer is used in Free call or a different pointer is used in alloc/free call.   Most common issues we have noticed is the Dangling pointer due to which the Magic number value which is written on the payload that number is overwritten using the alias pointer(Dangling pointer).