EmbLogic's Blog

identifiers

Identifiers are names for entities in a C program, such as variables, arrays, functions, structures, unions and labels. An identifier can be composed only of uppercase, lowercase letters, underscore and digits, but should start only with an alphabet or an underscore. If the identifier is not used in an external link process, then it is called as internal. Example: Local variable. If the identifier is used in an external link process, then it is called as external. Example: Global variable

An identifier is a string of alphanumeric characters that begins with an alphabetic character or an underscore character that are used to represent various programming elements such as variables, functions, arrays, structures, unions and so on. Actually, an identifier is a user-defined word

Posted in Uncategorized | Leave a comment

problem in qmake in Qt5.5

today i was about to start my first QT project  and after typing my first qt application ,

when i tried to qmake my project using ,

qmake -project

it was showing that couldn’t locate qmake

/usr/lib/i386-linux-gnu/qt4/bin/

so actually it was not able to locate the qmake command to make our project

and in qt 5.5 our qmake command is located at location :

/opt/Qt/5.5/gcc/bin/

so what i have to do is to install the default qt file using command

apt-get install qt5-default

so this will create a directory

/usr/lib/i386-linux-gnu/qt-default/

so it has a qmake file

simply open it and add your qmake file address to this file at the first place

/opt/Qt/5.5/gcc/bin/

then save the file and go to your project directory and give the qmake -project command

now your project will start to run your qmake commands

now you  can do your other following steps

it worked for me

thanks

varun

Posted in Uncategorized | Leave a comment

Library functions vs. System Calls

  • Standard functions can be divided in two main categories :-
    1. Library function calls.
    2. System function calls.
  • The functions which are a part of standard C library are known as Library functions. For instance, strcmp(), strlen() etc are all library functions.
  • The functions which change the execution mode of the program from user mode to kernel mode are known as system calls. For instance, socket(), open(), read() , write() etc are all system calls.
  • A library function is linked to the user program and executes in user space but a system call is not linked to a user program and executes in kernel space.
  • A library function execution time is counted in user level time but a system call execution time is counted as a part of system time.
  • Library functions can be debugged by using a debugger but System calls cannot be debugged because they are executed by the kernel.
Posted in Uncategorized | Leave a comment

Brief description about sockets attributes

Sockets are characterized by three attributes:  domain, type and protocol.

syntax:

#include<sys/types.h>

#include<sys/socket.h>

 

int socket(int domain, int type , int protocol);

  • socket domains: domain basically describes the network medium that is used by the sockets for communication. the most common domain used is AF_INET,  for Internet networking and AF_UNIX for UNIX file system domain used on a single  computer that isn’t networked.
  • socket types: In sockets, there are two methods for transferring data: stream and datagrams. stream sockets: It provides a connection link between the client and the server process.It is specified by the type SOCK_STREAM. datagrams: It provides the connectionless link between the client and server process. It is specified by the type SOCK_DGRAM.
  • socket protocols: protocols depends on the type of socket used. If socket type is SOCK_STREAM then TCP/IP protocol is used. If the socket type is SOCK_DGRAM then UDP/IP protocol is used.

 

Posted in Uncategorized | Leave a comment

Expression Parsing: Infix to postfix

#include<stdio.h>

int top=-1;
char stack[20];
void push(char ch)       //push function()
{
top++;                        // top is incremented
stack[top]=ch;           // character is pushed to stack
}
void pop()                    // pop function()
{
top–;                            // top is decremented
}
int main()
{
char arr[]={‘a’,’+’,’b’,’+’,’(‘,’c’,’*’,’d’,’)’,’+’,’(‘,’e’,’-’,’f’,’)’};          // general expression
int i,j=0,size_arr=sizeof(arr);                                                    // size of array
printf(“%s: Begin\n”,__FILE__);
printf(“%s: size of array is %d\n”,__FILE__,size_arr);
char post_arr[size_arr];                                       // array that saves the final postfix expression
printf(“///////////original expression//////////\n”);
printf(“%s”,arr);
for(i=0;i<size_arr;i++)
{
char ch=arr[i];                                                            // elements of array are one by one assigned to ‘ch’
if(ch==’+’ || ch==’-’ || ch==’*’ || ch==’/’ || ch==’(‘ || ch==’)’)   //ORing between characters
{
if(ch==’)’)                                        // if ‘ch’ is a closing brace
{
while(1)
{
post_arr[j]=stack[top];     // the character at the top of the stack is saved in the postfix array
j++;                                     // index of postfix array is incremented
pop();                                  // pop function called
if(stack[top]==’(‘)            // if top of the stack is an opening brace then pop is again called

{
pop();
break;
}
}
}
else
{
push(ch);     // if ‘ch’ is an operator other than closing brace then push the character in stack
}
}
else
{
post_arr[j]=ch;   // if ‘ch’ is not an operator then push the character in postfix array
j++;
}
}

while(top!=-1)         // when all the characters in original expression are once checked and are present in either stack or postfix array
{
post_arr[j]=stack[top];        // the leftover elements in stack are popped out and saved in postfix array
j++;                                      // index of array is incremented whereas top is decremented
top–;
}

printf(“\n/////////// Postfix expression//////////\n”);
printf(“%s”,post_arr);
printf(“\n%s: End\n”,__FILE__);
return 0;
}

Posted in Uncategorized | Leave a comment

Allocate a buffer aligned on a page boundary and initial protection is PROT_READ | PROT_WRITE

#include
#include
#include
#include
#include
#include
#include
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)

char *buffer;

static void handler(int sig, siginfo_t *si, void *unused)
{
printf(“Got SIGSEGV at address: 0x%lx\n”,
(long) si->si_addr);
exit(EXIT_FAILURE);
}

int main(int argc, char *argv[])
{
char *p;
int pagesize,i=0;
struct sigaction sa;

sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = handler;
if (sigaction(SIGSEGV, &sa, NULL) == -1)
handle_error(“sigaction”);

pagesize = sysconf(_SC_PAGE_SIZE);
if (pagesize == -1)
handle_error(“sysconf”);

/* Allocate a buffer aligned on a page boundary;
initial protection is PROT_READ | PROT_WRITE */

buffer = memalign(pagesize, 4 * pagesize);
if (buffer == NULL)
handle_error(“memalign”);

printf(“Start of region: 0x%lx\n”, (long) buffer);

if (mprotect(buffer + pagesize * 2, pagesize,
PROT_READ) == -1)
handle_error(“mprotect”);

for (p = buffer ; ; )
{
*(p++) = ‘a’;
printf(“Loop completed %d\n”,i); /* Should never happen */
i++;
}
printf(“Loop completed %d\n”,i); /* Should never happen */
exit(EXIT_SUCCESS);
}

Posted in Uncategorized | Leave a comment

Signal Handler for Segmentation fault.

#include
#include
#include
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
static void handler(int sig, siginfo_t *si, void *unused)
{
printf(“Got SIGSEGV at address: 0x%lx\n”,
(long) si->si_addr);
exit(EXIT_FAILURE);
}
int main()
{ int i=0;
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = handler;
//if (sigaction(SIGSEGV, &sa, NULL) == -1)
// handle_error(“sigaction”);
int *p=(int*)malloc(10*sizeof(int));
for(;;i++){

*(p+i)=i;
//printf(“%d\n”,i);
}
return 0;
}

Posted in Uncategorized | Leave a comment

Inter process Communication using Threads

1. Using Threads we can check the stack size and even allocate size according to our requirements using function call .stack management can be done using threads.

pthread_attr_getstacksize (&attr, &mystacksize);/ Initalize Stack for getting the size by using get stack size.

2. get stacksize is an attribute used here.

3.Client Server and Processing Client Synchronization can be done used using semaphore variable and mutex variable ,semaphore_wait is for incrementing the variable and semaphore_post is for decrementing the value in a process similarly mutex_lock and mutex unlock also works in the same way as incrementing and decrementing a variable.

4. In ipc while using fifo,pipes,msgqueue the data passes through the structure defined in kernel and data passes from user space to kernel space ,kernel space to user space .

5. There is problem of Block on read,write in fifo which can be avoided by using open command for reading and writing simultaneously for corresponding fifo.

From

NAKUL DHINGRA

 

 

 

 

Posted in Uncategorized | Leave a comment

Valgrind – a dynamic analysis and debuging tool.

Valgrind is a tool that provides ease to analyse and debug the errors in your c and c++ code’s. It provides various  tools such as:

1. Memory error detector (Memcheck).

2. Two thread error detector.

3. Cache prediction profiler (Cachegrind).

4. Call graph generating (callgrind).

5. Heap profiler (Massif).

Valgrind uses just-in-time complication techniques( JIT techniques).

Posted in Uncategorized | Leave a comment

How to Open Multi-Windows in VIM

Let you have thee files (say a.c  b.c  and c.c ) want to open in single vim editor.

  1. To do so open a program say a.c by vim a.c.
  2. Keeps in command mode( if not press Esc) window command ( Ctrl + w), now you will be in window mode.
  3. Press v or s for vertical and horizontal opening of same file.
  4. To open new program say b.c, type in command mode [:e file_name ]. You will fine a.c and b.c will open on vim editor simultaneous.
  5. To change curser from current one window to other : Types  go again in window mode [ Ctrl + w ] , then press arrow key in according to the direction of cursr transfer through the window( Mean left key for transfer of curser to leftward window and so on….)

Open Multiple Program in Single VIM Editor

Posted in Uncategorized | Leave a comment

Loop Control Statements

Loop control statements in C are used to perform looping operations until the given condition is true. Control comes out of the loop statements once condition becomes false.
There are 3 types of loop control statements in C language. They are,

1. for
2. while
3. do-while

Posted in Uncategorized | Leave a comment

About global variable

global variable is  diclared before main function .

It can used in all the functions  in a programe

Posted in Uncategorized | Leave a comment

Program on Array to delete the element

Firstly assign the values on local variable like;

int a[10],i,nul=0;

then values enter in the array by use of scanf;

scanf(“%d”,&a[i]);

then enter the value you want to delete;

now compare the entered value with the values of array;

after that ,if value is find then  assign the  nul value on the array.

then print the array

 

Posted in Uncategorized | Leave a comment

Array

In c Array is a collection of variables which is same data type. You can store group of data of same data type in an array.

Array might be belonging to any of the data types
Array size must be a constant value.
It is a best practice to initialize an array to zero or null while declaring, if we don’t assign any values to array.

Posted in Uncategorized | Leave a comment

makefile

all: d1 d2

d1: a.o
gcc -o a a.o
a.o: a.c
gcc -c a.c

d2: b.o
gcc -o b b.o
b.o: b.c
gcc -c b.c

clean:
-rm -rf a.o b.o shub
@mkdir -p shub
rm -rf a b

Posted in Uncategorized | Leave a comment