![]() |
|
Submit Programming Language Questions |
| C Questions | C++ Questions |
| COBOL Questions | Easytrieve Questions |
| Java Questions | .NET Questions |
| PL/1 Questions | REXX Questions |
| SAS Questions | XML Questions |
The Computer Education Techniques knowledge base is a service for answering questions, inclusive of the research and validation of the accuracy of information in the public domain. Citation of source documentation and examples are used to provide answers to the questions. Utilization of the information of this service and reliance on the answers, information or other materials received through this web site, is done at your own risk.
| Q |
My compiler is issuing errors relating to an
"invalid initializer".
What is wrong with this initialization: char *p = malloc(10); |
||||||||||||||
| A | Is the declaration of a static or non-local variable? Function calls are allowed in initializers only for automatic variables. The declaration must be for local, non-static variables. | ||||||||||||||
| Q |
What is the difference between these two
declarations? struct x1 {
... }; |
||||||||||||||
| A |
The first form declares a "structure tag"; the
second declares a "typedef". The main difference is the subsequent reference
to the first type is "struct x1" and the second type is as "x2". The second declaration is a slightly more abstract type; its users do not necessarily know that it is a structure, and the keyword struct is not used when declaring instances of it. |
||||||||||||||
| Q | Is there a way to compare structures automatically? | ||||||||||||||
| A |
No, there is not a good way for a compiler to
implement structure comparison which is consistent with a low level
language.
In order to compare two structures, it will be necessary to write a function, field by field, to do so. |
||||||||||||||
| Q | Why doesn't
the code the following code work?
int a = 1000, b = 1000; |
||||||||||||||
| A |
Under C's integral promotion rules, the
multiplication is carried out using int arithmetic, and the result may
overflow or be truncated before being promoted and assigned to the long int
left-hand side. An explicit cast can be used to force long arithmetic: long int c = (long int)a * b; |
||||||||||||||
| Q | Does C have "pass by reference"? | ||||||||||||||
| A |
C always uses pass by value. Accordingly, the
answer is that C does not truly have a pass by reference. It is possible to simulate pass by reference, by defining functions which accept pointers and then using the & operator when calling. The compiler will essentially provide the simulation when an array is passed to a function by passing a pointer instead. |
||||||||||||||
| Q | How can an array's size be set at run time? How can I avoid fixed-sized arrays? | ||||||||||||||
| A |
The equivalence between arrays and pointers
allows a pointer to malloc'ed memory to simulate an array.
After executing: #include <stdlib.h> and if the call to malloc succeeds, a
reference can be made to dynarray[i] (for i from 0 to 9) as if dynarray were
a conventional, statically-allocated array (int a[10]). The difference is that sizeof will not give the size of the "array". |
||||||||||||||
| Q |
Are there any free C compilers? |
||||||||||||||
| A |
A list of free c compilers includes:
|
||||||||||||||
| Q |
We are uncertain as to whether our organization's compiler supports ANSI-C++? |
| A |
Experience with another programming language is not a prerequisite for learning C++. As a result of the extensive use of special characters - {}[]*&!|..., code written in C++ gives the appearance of being more cryptic than some other languages. However, professional training will demonstrate that C++ is quite reasonable in its use of expressions and can be equally if not more straightforward than languages which rely on English words. Example: This code fragment uses the bool type, namespaces, and templates. #include <iostream> using namespace std; template <class T> bool ansisupported (T x) { return true; }
int main() { if (ansisupported(0)) cout << "ANSI OK"; return 0; } If the compiler is able to compile this program, then it will be able to compile most of the existing ANSI-C++ code. |
| Q |
What is an inline function? |
| A |
When the compiler inline-expands a function call, the function's code gets inserted into the caller's code stream. This is similar to what happens with a #define macro. There are several ways to designate that a function is inline, some of which involve the inline keyword. No matter how a function is designated as inline, it is a request that the compiler is allowed to ignore. The compiler might inline-expand some, all, or none of the calls to an inline function. This flexibility allows the compiler to treat large functions differently from small ones. It also allows the compiler to generate code that is easier to debug; this assumes that the appropriate compiler options have been selected. |
| Q |
Do inline functions improve performance? |
|
Explanation There are a significant number of considerations which will impact the degree of optimization, if any, in called code. Why inline functions might make code faster.
Why inline functions might make the code more concise and smaller.
Why inline functions might decrease the number of cache misses.
Why inline functions might prevent thrashing.
Why inline functions might make the code slower.
Why inline functions might increase the number of cache misses.
Why inline functions might be irrelevant to speed.
|
|
| A |
There are no general rules which will yield an optimal unambiguous positive result. The use of inline functions might make the code faster, it might make it slower. The executable larger can be larger or smaller. It might cause thrashing; it may prevent thrashing. Inline functions can have an unpredictable impact or be irrelevant in terms of speed. |
| Q | Is there a significant difference between List x; and List x();? |
|
Explanation by Example Assume that List is the name of some class. The function f() declares a local List object called x. void f() { List x; // Local object named x (of class List) ... } However, the function g() declares a function called x() that returns a List. void g() { List x(); // Function named x (that returns a List) ... } |
|
| A | There is a considerable difference in the two functions. |
| Q | Why are classes with static data members getting linker errors? |
| A |
Classes with static members are getting linker errors because static data members must be explicitly defined in one compilation unit. When this is not done, there in all likelihood will be an "undefined external" linker error. Example: // Fred.h class Fred { public: ... private: static int j_; // Declares static data member Fred::j_ ... }; The linker would state ("Fred::j_ is not defined") unless the definition has been made Fred::j_ in one of the source files. Example: // Fred.cpp #include "Fred.h" int Fred::j_ = some_expression_evaluating_to_an_int; // Alternatively, if you wish to use the implicit 0 value for static ints: // int Fred::j_; The usual place to define static data members of class Fred is file Fred.cpp or Fred.C or the source file extension in use. |
| Q | What is "self assignment"? |
| A |
Self assignment is when someone assigns an object to itself. Example: #include "Fred.h" // Defines class Fred void userCode(Fred& x) { x = x; // Self-assignment } This explicit self assignment is not practical; however, since more than one pointer or reference can point to the same object, which is known as aliasing, it is possible to have self assignment without knowing it. #include "Fred.h" // Defines class Fred void userCode(Fred& x, Fred& y) { x = y; // Could be self-assignment if &x == &y } int main() { Fred z; userCode(z, z); ... } |
|
COBOL |
|
| Q | Is the COBOL programming language still important and should I learn it? |
| A | It is common knowledge that the
high growth areas of application development in IT are Java and .NET.
However, the demand for COBOL programmers reflects an interesting imbalance
in the IT field. Over the past 40 years, there has been a huge investment in
the COBOL programming language and the colleges and IT graduate schools
either offer minimal instruction or have no courses on the COBOL programming
language and their curriculum do not teach advanced topics or third party
utilities. Since they can’t recruit COBOL programmers out of school, a
significant number of Fortune 1000 companies, government municipalities, and
health-care facilities have been using SYS-ED to “Grow their own COBOL
Programmers” for them. We offer intensive courses 5 days or less in duration
which can be mixed and matched into 2- and 3-week programs and a
comprehensive 6-week COBOL training program. Our staff has extensive
development experience across the complete range of proprietary COBOL
development platforms - IBM, Unisys, Micro Focus, Fujitsu, and CA-Realia.
The duration for these COBOL platform-specific courses varies based upon whether
the IT personnel to be trained is learning COBOL or learning how to code,
edit, compile, and debug on a new platform or workbench. Both the COBOL
courses offered through New York and our private courses reflect a
fast-track learning approach with flexible scheduling options (evenings,
weekends, and non consecutive weeks).
FYI, a similar situation exists with all the old line mainframe programming languages: Assembler, PL/1, and FORTRAN. SYS-ED has an extensive courseware library and 1000’s of programming examples and teach integrated curriculum for all of the legacy programming languages: basic, advanced, and debugging. |
| Q | How is the program compilation managed in a CA-Easytrieve program. |
| A | The PARM statement is used for customizing the operating environment during program compilation. The PARM statement, is an optional statement, it must be the first statement in your program. When Easytrieve is installed, compiler options are specified for the entire site. The PARM statement is used for overriding site options for a specific program. |
| Q | Easytrieve has a DMAP. Is this the same DMAP that is used in COBOL? |
| A | The DMAP is a data map which provides the location of file and work fields. The DMAP also reports the attributes of all files and fields in a Easytrieve program. The DMAP does perform the same function in COBOL; however, the Easytrieve program contains different information. |
| Q | How does Easytrieve control the printer after each detail line is printed? |
| A | The AFTER-LINE procedure can be coded for invocation after each individual line in a line group. The system-defined field LINE-NUMBER contains the number of the line in the group being processed. When the AFTER-LINE procedure is invoked, the detail line for the report has already been built. The contents of the detail line can not be modified with an AFTER-LINE procedure. There is also a BEFORE-LINE procedure that is invoked before each individual line in a line group. |
| Q | Does Easytrieve have a statement similar to the COBOL EVALUATE statement? |
| A | Yes. It has the CASE statement. The CASE and END-CASE statements are used for conditionally executing one of several alternative groups of statements based on the value of a specific field. A CASE statement can be nested within a CASE statement. Other conditional execution statements can also be nested within a CASE statement. |
| Q | Which command is used to create break processing in Easytrieve? |
| A | The CONTROL statement identifies control fields used for a report. A control break occurs whenever the value of any control field changes or end-of-report occurs. The control break at end-of-report is equivalent to the final break. A break level is also assigned to each control field. |
| Q | What are the FILE Fields provided by Easytrieve? |
| A | Easytrieve automatically
provides the following special data fields:
|
| Q | What is the purpose of the EXECUTE statement? |
| A | The EXECUTE
statement invokes a JOB, SORT, or SCREEN activity from either a PROGRAM
or SCREEN activity. The EXECUTE statement transfers control to an
activity. After the activity is executed, control returns to the next
executable statement following the EXECUTE.
A JOB, SORT, or SCREEN activity cannot be invoked in a JOB or SORT activity. EXECUTE statements in a SCREEN activity can invoke other activities; this is known as activity nesting. |
| Q | Are there advantages associated with using the OPTIMIZER compiler option? |
| A |
The advantages are: 1. Specifying the OPTIMIZE option will improve the speed of a program. 2. Choosing OPTIMIZE(2) directs the compiler to generate code for better performance.
3. Choosing OPTIMIZE(3) directs the compiler to generate even better code.
|
| Q | Senior members of our staff have informed me that the use of PUT DATA commands is very inefficient. What then is the reason for using PUT DATA commands? |
| A | PUT DATA statements can be invaluable for purposes of debugging at the cost of decreased performance. This cost to performance is usually very high when either GET DATA or PUT DATA is used without a variable list. |
|
Explanation by Example:
A reasonable practice is to use PUT DATA statements in ON ERROR code.
The program would be further optimized by including a list of selected variables with the PUT DATA statement. |
|
| Q | What is the REDUCIBLE option on a function? |
| A | REDUCIBLE indicates that a procedure or entry does not need to be invoked multiple times if the argument(s) stays unchanged, and that the invocation of the procedure has no side effects. |
Guideline:
|
|
| Q | Should, UNION or DEFINED be used in Enterprise PL/1? |
| A |
The UNION attribute is more powerful than the
DEFINED attribute and provides greater functionality. Some of the reasons for
using UNION as opposed to DEFINED include:
|
| Q | In PL/1 should named constants or static variables be used? |
| A |
Named constants are defined by declaring a variable
with the VALUE attribute. If static variables are used with the INITIAL
attribute and the variable is not altered, the variable should be declared a
named constant using the VALUE attribute.
The compiler does not treat NONASSIGNABLE scalar STATIC variables as true named constants. The compiler generates better code whenever expressions are evaluated during compilation; therefore the use of named constants can be used to produce efficient code with no loss in readability. |
| Q | What is the JNI: Java Native Interface? |
| A | JNI is the Java interface to native programming languages and is part of the Java Development Kits. Programs written to use the JNI, ensure that code is portable across many platforms. JNI allows Java code that runs within a JVM: Java Virtual Machine to operate with applications and libraries written in PL/1 and other languages. The Invocation API allows a Java Virtual Machine to be embedded into native PL/I applications. |
| Q | What XML parsers are available for PL/1? |
| A |
There are two major types of interfaces for XML
parsing: event-based and tree-based.
For an event-based API, the parser reports events to the application through callbacks such as the start of the document, the beginning of an element, etc. The application provides handlers to deal with the events reported by the parser. The Simple API for XML or SAX is an industry-standard event-based API. For a tree-based API, the parser translates the XML into an internal tree-based representation. Interfaces are provided to navigate the tree. IBM PL/I provides a SAX-like event-based interface for parsing XML documents. The parser invokes an application-supplied handler for parser events, passing references to the corresponding document fragments. The Document Object Model or DOM is a tree-based API. |
|
Legacy Programming Languages |
|
| Q | It is almost impossible to locate instructor-led programming language courses for the languages from the 1970’s and early 1980’s: Assembler Language, FORTRAN, PL/1, and RPG. My company requires a certain amount of maintenance programming to be performed on a regular basis. Does SYS-ED offer these courses? |
| A | Our staff of full-time instructors averages over 30 years of experience and has written and maintained programs in all of these programming languages. No independent training company has the comprehensive library of programming language courseware, sample programs, and training aids for legacy programming languages. Most of the courses are offered through our open enrollment schedule and all the courses, inclusive of multiple of tailored advanced topics are offered by request through our New York training centers. |
|
REXX |
|
| Q | I have been assigned to do REXX maintenance coding. It quickly has become apparent that I need to learn more than simply REXX in order to successfully perform my job. What other IBM systems software would it be helpful to be proficient with? |
| A | The following IBM systems
software typically been utilized in conjunction with REXX:
|
|
.NET versus Java |
|
| Q | In the 1990’s, our company made an extensive investment in the first generation Microsoft development languages and platform and more specifically Visual Basic. Management has made the decision has been made to standardize on the Java platform. What trade-offs/decisions should we explicitly consider as we both migrate our existing inventory of applications and develop new web based systems? |
| A | Depending on the existing skill level of your IT staff, the most efficient and cost effective approach would probably be an accelerated program over an intensive period ranging from 5 to 15 days. For private programs, which can offer cost effectively for groups as few four people, the content and workshops could be tailored to specific training requirements and migration projects. |
|
XML |
|||||||||
| Q | What is XML? Does my company need to modify our data and applications to it? | ||||||||
| A | XML is an open standard; it is
not defined or proprietary to any one company such as Windows by Microsoft,
WebSphere by IBM, or the Oracle database engine by Oracle Corporation. The
fundamental objective of the XML standard is to enable generic SGML to be
served, received, and processed on the Web in the same way that HTML
currently is utilized. SGML is the Standard Generalized Markup Language. It
is the international standard for defining descriptions of the structure of
different types of electronic document. The XML specification can be
downloaded. XML provides the following functionality:
All data on the web will at some point in the not so distant future be XML! |
||||||||