Tuesday, February 26, 2019

Software Developer

R N S INSTITUTE OF TECHNOLOGY CHANNASANDRA, BANGALORE 61 UNIX governing form PROGRAMMING NOTES FOR 6TH SEMESTER INFORMATION SCIENCE SUBJECT CODE 06CS62 active BY RAJKUMAR Assistant Professor Department of Information Science DIVYA K 1RN09IS016 6th Semester Information Science and Engineering emailprotected com Text Books 1 Terrence Chan Unix schema Programming Using C++, Prentice H entirely India, 1999. 2 W. Richard Stevens, Stephen A.Rago modernistic Programming in the UNIX Environment, 2nd Edition, Pearson Education / PHI, 2005 Notes have been circulated on self risk nobody send away be held responsible if whateverthing is wrong or is improper information or insufficient information provided in it. limit social unit 1, UNIT 2, UNIT 3, UNIT 4, UNIT 5, UNIT 6, UNIT 7 RNSIT UNIX SYSTEM PROGRAMMING NOTES UNIT 1 INTRODUCTION UNIX AND ANSI STANDARDS UNIX is a computer operating form originally developed in 1969 by a group of AT&T employees at Bell Labs, including aw arness Thompson, Dennis Ritchie, Douglas McElroy and Joe Ossanna.Today UNIX systems are split into various branches, developed over date by AT&T as well as various mercenary vendors and non-profit organizations. The ANSI C Standard In 1989, American National Standard build (ANSI) proposed C scheduleming language standard X3. 159-1989 to standardise the language constructs and libraries. This is termed as ANSI C standard. This attempt to unify the implementation of the C language back up on all computer system. The major differences between ANSI C and K&R C Kernighan and Ritchie are as follows ? procedure prototyping ? shop of the const and vaporific data grapheme qualifiers. Support spacious characters and internationalization. ? Permit dish cursors to be used without dereferencing. Function prototyping ANSI C adopts C++ forge effigy proficiency where sour definition and declaration take function names, arguments data types, and recall look on data types. This enables ANS I C compilers to check for function calls in user programs that pass handicap outcome of arguments or in congruous arguments data type. These dumbfound a major weakness of K&R C compilers invalid function calls in user programs often pass compilation just now if cause programs to crash when they are executed.Eg unsigned long foo(char * fmt, double data) /*body of foo*/ unsigned long foo(char * fmt, double data) eg int printf(const char* fmt,.. ) External declaration of this function foo is find variable number of arguments Support of the const and volatile data type qualifiers. ? The const keyword declares that some data cannot be changed. Eg int printf(const char* fmt,.. ) Declares a fmt argument that is of a const char * data type, gist that the function printf cannot modify data in any character array that is passed as an actual argument determine to fmt.Volatile keyword specifies that the enured of some variables may change asynchronously, giving an hint to the co mpilers optimization algorithm not to remove any purposeless dictations that involve volatile objects. char get_io() volatile char* io_port = 0x7777 char ch = *io_port /* cross-file first byte of data*/ ch = *io_port /*read second byte of data*/ ? eg If io_port variable is not declared to be volatile when the program is compiled, the compiler may lead second ch = *io_port statement, as it is considered redundant with respect to the previous statement. Prepared By RAJKUMAR Asst. Prof. & DIVYA K 1RN09IS016 Page 1 RNSIT UNIX SYSTEM PROGRAMMING NOTES The const and volatile data type qualifiers are to a fault supported in C++. Support wide characters and internationalisation ? ? ANSI C supports internationalisation by allowing C-program to use wide characters. Wide characters use more than one byte of storage per character. ANSI C defines the setlocale function, which allows users to specify the format of involvement, monetary and real number representations. For eg most countries introduction the date in dd/mm/yyyy format whereas US displays it in mm/dd/yyyy format. Function prototype of setlocale function is ? include char setlocale (int category, const char* locale) ? The setlocale function prototype and realizable values of the category argument are declared in the header. The category values specify what format class(es) is to be changed. Some of the possible values of the category argument are category value ready on standard C functions/ bigs LC_CTYPE LC_TIME LC_NUMERIC LC_MONETARY LC_ALL ? ? ? ? ? Affects behavior of the macros Affects date and time format. Affects number representation format Affects monetary values format combines the affect of all above Permit function pointers without dereferencing ANSI C specifies that a function pointer may be used like a function name.No referencing is needed when calling a function whose address is contained in the pointer. For Example, the following statement given below defines a function pointer funptr , which contains the address of the function foo. extern void foo(double xyz,const int *ptr) void (*funptr)(double,const int *)=foo The function foo may be invoked by either directly calling foo or via the funptr. foo(12. 78, how-do-you-do world) funptr(12. 78, how-do-you-do world) K&R C requires funptr be dereferenced to call foo. (* funptr) (13. 48,Hello usp) ANSI C also defines a set of C processor(cpp) symbols, which may be used in user programs.These symbols are assigned actual values at compilation time. cpp SYMBOL USE _STDC_ Feature test macro. revalue is 1 if a compiler is ANSI C, 0 otherwise _LINE_ Evaluated to the physical cablegram number of a source file. _FILE_ Value is the file name of a module that contains this symbol. _DATE_ Value is the date that a module containing this symbol is compiled. _TIME_ value is the time that a module containing this symbol is compiled. The following test_ansi_c. c program illustrates the use of these symbols include int main() if _ST DC_==0 printf(cc is not ANSI C tractable) else printf(%s compiled at %s%s.This statement is at line %d , _FILE_ , _DATE_ , _TIME_ , _LINE_ ) endif Return 0 Prepared By RAJKUMAR Asst. Prof. & DIVYA K 1RN09IS016 Page 2 RNSIT ? UNIX SYSTEM PROGRAMMING NOTES Finally, ANSI C defines a set of standard depository library function & associated headers. These headers are the subset of the C libraries available on most system that implement K&R C. The ANSI/ISO C++ Standard These compilers support C++ classes, derived classes, virtual functions, operator overloading. Furthermore, they should also support template classes, template functions, ejection handling and the iostream library classes.Differences between ANSI C and C++ ANSI C Uses K&R C default function declaration for any functions that are referred before their declaration in the program. int foo() ANSI C treats this as old C function declaration & interprets it as declared in following manner. int foo(.. ) ? meaning that foo may be called with any number of arguments. Does not employ type_safe gene linkage technique and does not catch user errors. C++ Requires that all functions must(prenominal) be declared / defined before they can be referenced. int foo() C++ treats this as int foo(void) Meaning that foo may not arguments. accept anyEncrypts external function names for type_safe linkage. Thus reports any user errors. The POSIX standards ? POSIX or Portable run System Interface is the name of a family of related standards specified by the IEEE to define the application-programming interface (API), along with shell and utilities interface for the software compatible with variants of the UNIX operating system. Because many versions of UNIX exist today and each of them provides its own set of API functions, it is difficult for system developers to create applications that can be easily ported to diametric versions of UNIX.Some of the subgroups of POSIX are POSIX. 1, POSIX. 1b & POSIX. 1c are concerned with the development of set of standards for system developers. POSIX. 1 ? This direction proposes a standard for a base operating system API this standard specifies APIs for the manipulating of files and processes. ? It is formally known as IEEE standard 1003. 1-1990 and it was also adopted by the ISO as the international standard ISO/IEC 994511990. POSIX. 1b ? This committee proposes a set of standard APIs for a real time OS interface these include IPC (interprocess communication). ? This standard is formally known as IEEE standard 1003. -1993. POSIX. 1c ? This standard specifies multi-threaded programming interface. This is the newest POSIX standard. ? These standards are proposed for a generic OS that is not necessarily be UNIX system. ? E. g. VMS from Digital Equipment smoke, OS/2 from IBM, & Windows NT from Microsoft Corporation are POSIX-compliant, yet they are not UNIX systems. ? To ensure a user program conforms to POSIX. 1 standard, the user should either define the manifes ted never-ending _POSIX_SOURCE at the beginning of each source module of the program (before inclusion of any header) as define _POSIX_SOURCE ? ? ? ? Or specify the -D_POSIX_SOURCE option to a C++ compiler (CC) in a compilation % CC -D_POSIX_SOURCE *. C ? POSIX. 1b defines several(predicate) manifested constant to check conformance of user program to that standard. The new macro is _POSIX_C_SOURCE and its value indicates POSIX version to which a user program conforms. Its value can be Prepared By RAJKUMAR Asst. Prof. & DIVYA K 1RN09IS016 Page 3 RNSIT _POSIX_C_SOURCE determine 198808L 199009L 199309L MEANING UNIX SYSTEM PROGRAMMING NOTES First version of POSIX. compliance support version of POSIX. 1 compliance POSIX. 1 and POSIX. 1b compliance ? _POSIX_C_SOURCE may be used in place of _POSIX_SOURCE. However, some systems that support POSIX. 1 only may not accept the _POSIX_C_SOURCE definition. ? There is also a _POSIX_VERSION constant defined in header. It contains the POSIX ver sion to which the system conforms. Program to check and display _POSIX_VERSION constant of the system on which it is run define _POSIX_SOURCE define _POSIX_C_SOURCE 199309L include include int main() ifdef _POSIX_VERSION cout

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.