Preprocessor Directives 365
11.10 INLINE DIRECTIVE
Reports the compiler that the source code has in line asm statements. It is important to know
previously that the source code contains assembly code.
11.11 THE #pragxna SAVEREGS
Guarantees that a huge function will not modify the value of any of the registers when it is entered.
Place this directive immediately preceding the function definition.
11.12 THE #pragma DIRECTIVE
The A N S I-C and T U R B O -C provide pragma directives. These #pragma directives are defined
with # (hash) and these are the preprocessor directives. These directives deal with formatting
source listing and placing components in the object file generated by the compiler. It sets /resets
certain warning and errors during compilation of C program. Tables 11.1,11.2,11.3 and 11.4 describe
the different pragma names with error messages.
Syntax
# pragma warn + xxx
# pragma warn -xxx
Where the first statement turns on the warning message and the second statement sets off the warning
message.
Table 11.1 ANSI Violations and #pragma
#pragma name Warning On
Warning off
Hexadecimal or octal constant too large +big
-b ig
Redefinition not identical
+dup
- dup
Both return and return of a value used
+ret
-ret
Not part of structure
+str
-str
Undefined structure
+stu -stu
Suspicious pointer conversion
+S US -sus
Void functions cannot return a value
+voi
-voi
Zero length structure
+zst
-zst
Table 11.2 Common Errors and #pragma
#pragmaname
Warning On Warning off
Assigned a value but never used
+aus -aus
Possible use before definition
+def -def
Code has no effect
+eff -eff
Parameter never used
+par
-par
Possibly incorrect assignment
+pia -pia
Unreachable code
+rch
-rch
Function should return a value
+rvl
-rvl
Ambiguous operators need parentheses
+anb
-amb
366 Programming and Data Structures
Table 11.3 Less Common Errors and #pragma
# pragma name
Warning On Warning off
Superfluous & with function or array
+amp -amp
No declaration for function
+nod
-nod
Call to function with no prototype
+pro -pro
Structure passed by value
+stv -st v
Declared but never used
+use -use
Table 11.4 Portability Warnings and #pragma
#pragmaname
Warning On
Warning off
Nonportable pointer assignment
+apt -apt
Constant is long
+cln -cln
Non-portable pointer comparison
+cpt -cpt
Constant out of range in comparison
+rng -rng
Non-portable pointer conversion
+rpt -rp t
Conversion can lose significant digits +sig -sig
Mixing pointers to signed and unsigned char +ucp -ucp
11.14 Write a program to set off certain errors shown by the program using #pragma directives.
# include <stdio.h>
# include <canio.h>
#pragma warn -aus
#pragma warn -d e f
#pragma warn -r o l
#pragma warn - use
xn&inO
{
int x»2,y,z;
printf (* y« %d" ,y) ;
}
Explanation The above program contains following warnings.
1) Possible use o f'y ' before definition in function.
2) z declared but never used in function main.
3) 'x' is assigned a value which is never used in function.
4) Function should return a value in function main.
The display of these warning messages can be made on or off by setting the pragma options. In the
above program the four pragma options are set to off. Hence, after compilation the above listed lines
will not be displayed. If the four pragma options are set the compiler displays these warning messages.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.156.93