Programming languages concepts 6 Please let me know if you need more time. Thank
ID: 639323 • Letter: P
Question
Programming languages concepts 6
Please let me know if you need more time. Thank you in advance!
A. In the C language, programs often include standard headers by using the #include directive. For example, the following directive includes the header: #include (a) Give the name of one C89 standard header that did not exist in K&R; C. (b) Give the name of one C99 standard header that did not exist in C89. Note: ''K&R; C'' refers to the language as defined in Kernighan and Ritchie's The C Programming Language (1978). ''C89'' refers to the language as it was standardized in 1989. ''C99'' refers to the standard that was approved in 1999. C. Ada is based on Pascal, but lacks some Pascal features. List two of them.Explanation / Answer
A)Controlling Diagnostics in System Headers
Warnings are suppressed when they occur in system headers. By default, an included file is treated as a system header if it is found in an include path specified by -isystem, but this can be overridden in several ways.
The system_header pragma can be used to mark the current file as being a system header. No warnings will be produced from the location of the pragma onwards within the same file.
The --system-header-prefix= and --no-system-header-prefix= command-line arguments can be used to override whether subsets of an include path are treated as system headers. When the name in a #include directive is found within a header search path and starts with a system prefix, the header is treated as a system header. The last prefix on the command-line which matches the specified header name takes precedence. For instance:
Precompiled Headers
Precompiled headers are a general approach employed by many compilers to reduce compilation time. The underlying motivation of the approach is that it is common for the same (and often large) header files to be included by multiple source files. Consequently, compile times can often be greatly improved by caching some of the (redundant) work done by a compiler to process headers. Precompiled header files, which represent one of many ways to implement this optimization, are literally files that represent an on-disk cache that contains the vital information necessary to reduce some of the work needed to process a corresponding header file. While details of precompiled headers vary between compilers, precompiled headers have been shown to be highly effective at speeding up program compilation on systems with very large system headers (e.g., Mac OS X).
Generating a PCH File
To generate a PCH file using Clang, one invokes Clang with the -x <language>-header option. This mirrors the interface in GCC for generating PCH files:
Using a PCH File
A PCH file can then be used as a prefix header when a -include option is passed to clang:
The clang driver will first check if a PCH file for test.h is available; if so, the contents of test.h (and the files it includes) will be processed from the PCH file. Otherwise, Clang falls back to directly processing the content of test.h. This mirrors the behavior of GCC.
Note
Clang does not automatically use PCH files for headers that are directly included within a source file. For example:
In this example, clang will not automatically use the PCH file for test.h since test.h was included directly in the source file and not specified on the command line using -include.
Relocatable PCH Files
It is sometimes necessary to build a precompiled header from headers that are not yet in their final, installed locations. For example, one might build a precompiled header within the build tree that is then meant to be installed alongside the headers. Clang permits the creation of
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.