Chapter 19

 < Day Day Up > 



Chapter 18

  1. (T/F) C enables programmers to overload function names.

    FALSE

  2. What is the purpose of the extern linkage specification?

    To prevent the C++ compiler from name mangling a C (or other) language function declaration.

  3. What is name mangling and why do C++ compilers employ this technique?

    All identifier names in memory must be unique. In order to overload functions C++ must mangle the names of functions.

  4. List and describe the steps required to create a C function library.

    Step 1 - Put the function declarations for any functions you want in the library in a header file. (.h file)

    Step 2 - Put the definitions for the library functions in a separate implementation file. (.c file)

    Step 3 - Create an empty project in your Integrated Development Environment and add the implementation file to it.

    Step 4 - Add any library files to the project required to support the implementation file.

    Step 5 - Set the required target settings for the project.

    Step 6 - Name the library output file and set project type.

    Step 7 - Compile the project.

    Step 8 - Use the library!

  5. List and describe the four issues to consider before using assembly language in your programs.

    Efficient Processor Usage - Old assembly language routines may not use modern processors efficiently. As a rule, new processor versions introduce new instructions. Old versions of assembly language will most certainly not support these new instructions.

    Code Optimization - Face it...compilers generate better optimized code than do humans. If your reasons for using assembly include the one 'I can do it better...' I recommend letting the compiler have a go at it first.

    Portability - Adding assembly to your C++ program will lock it into a specific processor and severely limit your code portability.

    Maintenance - As time passes, assembly routines embedded directly in your C++ code will have to be upgraded more frequently than the C++ instructions to take advantage of new processor features.

  6. What C++ keyword allows you to embed assembly language in the body of C++ functions?

    asm (but if and how you can embed assembly language is compiler dependent, check with your compiler documentation)

  7. (T/F) All C++ compilers implement the capability to include assembly language in the body of functions the exact same way.

    FALSE

  8. List and describe the steps required to create, compile, and link an assembly language module to a C++ program.

    Step 1 - Create assembly language file with a text editor and save it with the .asm extension,

    Step 2 - Assemble the file to create a Portable Executable/Common Object File Format (PE/ COFF) object file,

    Step 3 - Create a C++ project using the development system of your choice,

    Step 4 - Create a header file that declares the name of the function contained in the object file. The function declaration must be declared to have extern 'C' language linkage.

    Step 5 - Add the object file to the C++ project,

    Step 6 - Compile and run the project and do a victory dance!

  9. What is the purpose of the javah command line tool?

    To automatically generate header files for native functions from the Java class specification.

  10. List and describe the steps required to call C++ functions from a Java program using the Java Native Interface (JNI).

    Step 1 - Create a Java source file that declares a class with one or more native methods. In addition to any native methods this class requires it also must also load the native dynamic library module using the System.loadLibrary() function.

    Step 2 - Compile the Java source file to create a .class file.

    Step 3 - Use the javah compiler with the -jni switch to automatically create a header file for use in your C++ program.

    Step 4 - Create a C++ source file that implements the native method.

    Step 5 - Compile the C++ source file to create a dynamic library that exports the native method.

    Step 6 - Run the Java program using the java virtual machine and do a victory dance!

  11. Under what circumstances would it not be a good idea to call a native C++ function from a Java program?

    If the native function did something small and needed to be called often.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net