Wednesday, May 6, 2020

Software Developer Free Essays

R N S INSTITUTE OF TECHNOLOGY CHANNASANDRA, BANGALORE – 61 UNIX SYSTEM PROGRAMMING NOTES FOR 6TH SEMESTER INFORMATION SCIENCE SUBJECT CODE: 06CS62 PREPARED BY RAJKUMAR Assistant Professor Department of Information Science DIVYA K 1RN09IS016 6th Semester Information Science and Engineering 1rn09is016@gmail. com Text Books: 1 Terrence Chan: Unix System Programming Using C++, Prentice Hall India, 1999. 2 W. We will write a custom essay sample on Software Developer or any similar topic only for you Order Now Richard Stevens, Stephen A. Rago: Advanced Programming in the UNIX Environment, 2nd Edition, Pearson Education / PHI, 2005 Notes have been circulated on self risk nobody can be held responsible if anything is wrong or is improper information or insufficient information provided in it. Contents: 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 system originally developed in 1969 by a group of ATT employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McElroy and Joe Ossanna. Today UNIX systems are split into various branches, developed over time by ATT as well as various commercial vendors and non-profit organizations. The ANSI C Standard In 1989, American National Standard Institute (ANSI) proposed C programming 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 supported on all computer system. The major differences between ANSI C and KR C [Kernighan and Ritchie] are as follows: ? Function prototyping ? Support of the const and volatile data type qualifiers. Support wide characters and internationalization. ? Permit function pointers to be used without dereferencing. Function prototyping ANSI C adopts C++ function prototype technique where function definition and declaration include function names, arguments’ data types, and return value data types. This enables ANSI C compilers to check for function calls in user progr ams that pass invalid number of arguments or incompatible arguments’ data type. These fix a major weakness of KR C compilers: invalid function calls in user programs often pass compilation but 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 specify 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, meaning that the function printf cannot modify data in any character array that is passed as an actual argument value to fmt. Volatile keyword specifies that the values of some variables may change asynchronously, giving an hint to the compiler’s optimization algorithm not to remove any â€Å"redundant† statements that involve â€Å"volatile† objects. char get_io() { volatile char* io_port = 0x7777; char ch = *io_port; /*read 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 eliminate 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 also 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 t he setlocale function, which allows users to specify the format of date, monetary and real number representations. For eg: most countries display 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 possible 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 effect on standard C functions/macros 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,†Hello world†); funptr(12. 78,†Hello world†); KR 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. Value is 1 if a compiler is ANSI C, 0 otherwise _LINE_ Evaluated to the physical line 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 _STDC_==0 printf(â€Å"cc is not ANSI C compliant†); #else printf(â€Å"%s compiled at %s:%s. This statement is at line %d †, _FILE_ , _DATE_ , _TIME_ , _LINE_ );

No comments:

Post a Comment

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