Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Assignment 01

Qno: 01
List of Portable Compilers and differentiate any five
of them?

The Portable C Compiler (also known as pcc or sometimes pccm - portable C


compiler machine) is an early compiler for the C programming language written
by Stephen C. Johnson of Bell Labs in the mid-1970s. Being one of the first
compilers that could easily be adapted to output code for different computer
architectures, the compiler had a long life span. It debuted in Seventh Edition
Unix and shipped with BSD Unix until the release of 4.4BSD in 1994, when it was
replaced by the GNU C Compiler. It was very influential in its day. These are some
portable compliers.

 BDS Unix
 GCC
 GNU
 Interactive C
  Visual Express
 Clang

GNU:
The GNU Compiler Collection (GCC) is an optimizing compiler produced by
the GNU Project supporting various programming languages, hardware
architectures and operating systems.
BDX:
The Berkeley Software Distribution or Berkeley Standard Distribution. BSD
was initially called Berkeley Unix because it was based on the source code of
the original Unix developed at Bell Labs. In the 1980s, although these
proprietary BSD derivatives were largely superseded in the 1990s by
UNIX SVR4 and OSF/1, later releases provided the basis for several open-
source operating systems 
GCC:
GNU Compiler Collection is the compiler produced by the GNU Project. This
supports many programming languages and it is a free software foundation
under the General Public License. This compiler was first released in 1987 and
it supported only C- Programming language during the start. Slowly it
expanded to C++, Java, Android, and IOS. Here, each of the different language
compilers has its own program that reads the code written and sends the
machine code as the output. All of these have a common internal structure. 
Clang:
Clang; including C, is also a compiler for C++, Objective-C, and objective C++
programming languages. This compiler uses LLVM for the back end code
related compilations. Clang has many contributors including Apple, Microsoft,
Google, Sony, and Intel. It is open-source software. LLVM was first used by
GCC for the front end compilation, but GCC had caused some problems for
developers at Apple, as the source code is large and difficult to use. So, they
had come up with Clang.
Qno: 02
What is Hash Table? Explain the working of Hash
Table?

Hash Table:
Hash Table is a data structure which stores data in an associative manner. In a
hash table, data is stored in an array format, where each data value has its own
unique index value. Access of data becomes very fast if we know the index of the
desired data. it becomes a data structure in which insertion and search operations
are very fast irrespective of the size of the data. Hash Table uses an array as a
storage medium and uses hash technique to generate an index where an element is
to be inserted or is to be located from.

Working of Hash Table:

Hashing is a technique to convert a range of key values into a range of indexes of


an array. We're going to use modulo operator to get a range of key values.
Consider an example of hash table of size 20, and the following items are to be
stored. Item are in the (key, value) format.

 (1,20)
 (2,70)
 (42,80)
 (4,25)
 (12,44)
 (14,32)
 (17,11)
 (13,78)
 (37,98)

Sr.No. Key Hash Array Index

1 1 1 % 20 = 1 1

2 2 2 % 20 = 2 2
3 42 42 % 20 = 2 2

4 4 4 % 20 = 4 4

5 12 12 % 20 = 12 12

6 14 14 % 20 = 14 14

7 17 17 % 20 = 17 17

8 13 13 % 20 = 13 13

9 37 37 % 20 = 17 17

Qno: 03
What's the meaning of GNU, GCC, POSIX in
compiler? Explanation required with example?
GNU:
GNU stands for GNU's Not UNIX. It is a UNIX like computer operating system,
but unlike UNIX, it is free software and contains no UNIX code. It is pronounced
as guh-noo. Sometimes, it is also written as GNU General Public License. It is
based on the GNU Hurd kernel and It is intended to develop and share software for
free, for all its users. The main objective of GNU was to provide free software.
Due to its similar design to UNIX, it is named as UNIX like computer system but it
contains no UNIX code. It is available in multiple language
This compiler comes by default with most *nix based operating systems, so if you
have installed and/or using Unix or Linux based operating system, in your system,
then you can find and use it easily.
For compiling your source code using GNU C compiler, you need to write like
this:
gcc program_name

GCC:
GCC stands for GNU Compiler Collections which is used to compile mainly C and
C++ language. It can also be used to compile Objective C and Objective C++. The
most important option required while compiling a source code file is the name of
the source program, rest every argument is optional like a warning, debugging,
linking libraries, object file etc. The different options of gcc command allow the
user to stop the compilation process at different stages. 
gcc [-c|-S|-E] [-std=standard]

Example:
This will compile the source. c file and give the output file as a.out file which is
default name of output file given by gcc compiler, which can be executed
using ./a.out 
 
gcc source.c

POSIX:
The POSIX thread libraries are a standards based thread API for C/C++. It allows
one to spawn a new concurrent process flow. It is most effective on multi-
processor or multi-core systems where the process flow can be scheduled to run on
another processor thus gaining speed through parallel or distributed processing.
Threads require less overhead than "forking" or spawning a new process because
the system does not initialize a new system virtual memory space and environment
for the process. While most effective on a multiprocessor system, gains are also
found on uniprocessor systems which exploit latency in I/O and other system
functions which may halt process execution. (One thread may execute while
another is waiting for I/O or some other system latency.) Parallel programming
technologies such as MPI and PVM are used in a distributed computing
environment while threads are limited to a single computer system. All threads
within a process share the same address space. A thread is spawned by defining a
function and it's arguments which will be processed in the thread. The purpose of
using the POSIX thread library in your software is to execute software faster.

Example:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *print_message_function( void *ptr );

main()
{
pthread_t thread1, thread2;
char *message1 = "Thread 1";
char *message2 = "Thread 2";
int iret1, iret2;

/* Create independent threads each of which will execute function */

iret1 = pthread_create( &thread1, NULL, print_message_function, (void*)


message1);
iret2 = pthread_create( &thread2, NULL, print_message_function, (void*)
message2);

/* Wait till threads are complete before main continues. Unless we */


/* wait we run the risk of executing an exit which will terminate */
/* the process and all threads before the threads have completed. */

pthread_join( thread1, NULL);


pthread_join( thread2, NULL);

printf("Thread 1 returns: %d\n",iret1);


printf("Thread 2 returns: %d\n",iret2);
exit(0);
}

void *print_message_function( void *ptr )


{
char *message;
message = (char *) ptr;
printf("%s \n", message);
}

Compile:
 C compiler: cc -lpthread pthread1.c
or
 C++ compiler: g++ -lpthread pthread1.c

Run: ./a.out
Results:
Thread 1
Thread 2
Thread 1 returns: 0
Thread 2 returns: 0

The End

You might also like