Posts

linker study material

 https://lwn.net/Articles/276782/

OS Books

 https://github.com/iceqp/books-1/blob/master/The%20Design%20and%20Implementation%20of%20the%20FreeBSD%20Operating%20System%20(2nd%20Edition).pdf

Array Boxing

  a[a[a[a[0]]]] c is encrypting b array and b array is encrypting a array a[b[c[i]]] a[a[a[a[i]]]] == i then it's cyclic in nature

Good Practices in C programming

  Use void* for pushing structures or datatype is unknown realloc and memcpy can be used together for editing or changing the size of existing data types specially for strings and designing string library. Always try to copy string to new array or dynamic array rather then assigning the base pointer of the array in C as string manipulation will become tough using pointer. use dynamic array, dynamic stack, string, dictionary, priority queues,  tuples as data structures by creating library always initialize a string with calloc so that '\0' char is assigned to each index in string array for a linked list to be used again use erase() to clean all linked list nodes always use strncpy/strncmp instead of strcpy/strcmp Always set '\0' at the last index of string/char array Don't expect copy-on-write in C and don't try to rewite a string in C rewriting an existing character array often leads to crashes , due to array out of bounds always to try to allocate & copy to...

Calling Conventions

  https://en.wikipedia.org/wiki/X86_calling_conventions cdecl stdcall

How to debug if you have difference in 2 repos that have 7-8 repo in between

 Just download all the repos and check git log or hg log   1st repo HD_R6201 & 2nd repo BBDR2014 the 1st repo has the bug then check the date in between where submissions are missing in 1st repo then goto 2nd repo check all the fixes that have been commited if not then check all intermediate or in between repos or branches Incase of emergency check in 1 repo above HD_R6201 that is HD_R6301 Check the exact scenario must match 

Important mercurial commnads

 hg diff -r <changeset-no1>:<changeset-no1+1> example :- hg diff -r 66237:66238 hg log --keyword "call" (will search all the commits with "call" in discription hg diff -c <commit-id> hg log -r <CS ID> --debug   (to know the commit details and branch name) example:- starting pager for command 'log' changeset: 14986:3b584f4ea27ebe6178c81d74767fe0f24290377b branch: cvp95 phase: public parent: 14985:762a72f7821ca441f5d0a3975eff344dd5a0e8a5 parent: -1:0000000000000000000000000000000000000000 manifest: 14918:d778007144b782255b9b1c0c56bc9a43f635e594 user: crzhang <crystal.zhang@nokia-sbell.com> date: Fri Dec 25 15:14:28 2020 +0800 files: SIP_PAL/pal/callmgnt/pal_callmgnt_wtconnect_state.cpp extra: branch=cvp95 description: BBDPROD-7552:Tight couple ONT IncomingTotalCallTime/TotalCallTime node does not work in call hold scenario

Good tools

OP Auto Clicker ghidra-sre.org SecureCRT  https://crackpur.com/securecrt-crack/ crontab (running program at interval) entr Lauterbach RTLinux Redox os/VxWorks Visual Studio CLion  tftp/ftp/scp ag (silver searcher) - https://www.cyberciti.biz/open-source/command-line-hacks/ag-supercharge-string-search-through-directory-hierarchy/ cscope ctags Mobaxterm Beyond compare/meld Hyperterminal/Tera Term(for modem connection) bitbucket/git/Jira/Confluence powershell can also be alternative of Hyperterminal(https://social.technet.microsoft.com/Forums/ie/en-US/2980f24e-56d1-431f-aedc-811c087b5184/powershell-serial-com-port?forum=ITCG)

Why C is the most powerful language

  Modularity and less keyword unlike other languages that have dedicated keyword for simple math functions,   it has libraries more instead of keywords   that makes it   efficient . Complex Declarations   , using complex declaration you can define any real world entity Storage classes such as extern & register, inline, volatile, const keyword which are low level in nature etc. Direct   mapping of constructs to memory segments Pointers with   Pointer typecasting & treating Function name as pointer ,   i think pointers are useless without pointer typecasting. Function name is treated as pointer in C which makes it very powerful and also pointer arithmetic. Wide varieties of types   from long long to char , floating type such as float or double but has   weak type checking. void * / int * as a generic data storage Use of   expression   in every place whether it’s in   for , while or if for(expression ; expression; e...

Firmware Interview Questions

 He asked a puzzle that you have 500 switches and all are OFF. Now someone came and make all of them ON. Now a second person came and flip all the second switch and then 3rd came and flip all the 3rd switch and so on till 500. So tell me how many switch will be on after completing the entire process. synchronization mechanisms for threads associating a mutex with a condition variable solved it mutex reursive binary semaphore and mutex Clone a linked list into two different linked lists such that one list contains the first half of the existing linked list, in the same order, and the other list contains the other half. Time complexity should be minimum. How would you represent a sparse matrix using minimum space complexity such that all elements can be accessed through their row and column indices? Prepare a STAR matrix parse matrix. C programming to the depth. like triple pointers, linked lists, algorithms etc. 1st F2F was on checking the logical ability and problem solving along w...

Basic Parsing using strtok

  C string.h library provides functionalities for parsing like strtok() string tokenizer is a functionality which will tokenize the string using the delimiter It basically replaces the delimiter string(char *) with '\0' next time we do strtok we give NULL as input instead of char* token with delimiter string.  char *strtok(char *token, char* delimiter);  Usage of strtok in Computer Networks for IP Address Parsing #include <string.h> #include <stdio.h> #include <stdlib.h> int main() {   int val;   char c[64]="192.168.0.0";  // be careful it should be character array not character pointer   char *tok;   tok=strtok(c,".");   while(tok != NULL)   {      val = atoi(tok);      printf("%s %d %x %o\n",tok,val,val,val);      tok=strtok(NULL,".");   } }   Wide application of strtok can be used for questions like:- " I LOVE MY COUNTRY " " COUNTRY MY LOVE I" ...

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).