![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
The C/C++ Editor The C/C++ editor is a text editor with special features for editing C/C++ source files. Note that this version of the C/C++ editor is the Apex text editor. This editor is only available with Rational Apex C/C++ and Rational Apex Duo.
About This Chapter
This chapter describes the C/C++ editor and shows how to use it. Specifically, this chapter covers the following topics:
This chapter describes the commands available from the Apex C/C++ editor's File, Edit, View, Navigate, and Compile menus. The Control menu is examined in Using and Customizing Summit/CM and the Debug menu is described in Using the Apex Debugger.
The C/C++ Editor WindowThe C/C++ editor window is similar to the text-editor window described in The Apex Text Editor.
The C/C++ editor is used to create, view, and edit C/C++ source code.
Note: The C++ editor was designed using the standard Motif text widget, so its basic editing commands are similar to those of many other Motif clients (and emacs, too). Some keystroke combinations recognized by the Apex editor are actually accelerators for the commands on the Edit menu.
Starting the C/C++ EditorThere are several ways to start the C/C++ editor. You can:
- Create a new C/C++ file by selecting the File > New > New C++ or the File > New > New C command.
- Open an existing C/C++ file in an editor window by selecting the Open command from the File menu.
Apex then displays an Open dialog box, which you can use to open the C/C++ file. (To learn how to use the Open dialog box, see Using and Customizing the GUI.)
- Open an existing C/C++ file in an editor window by selecting the file from the Apex directory-viewer window.
To learn how to use the directory-viewer window, see Using and Customizing the GUI.
Editing Source CodeThe editing commands recognized by the C/C++ editor are the same as those recognized by the Apex text editor described in The Apex Text Editor. By choosing commands from the Edit menu, you can:
- Perform standard delete, cut, copy, and paste commands
- Undo editing commands that have been issued in error
- Reinstate editing commands that have been undone using the Undo command
- Search text displayed in the editor window for specified patterns and expressions
- Comment out text in C/C++ source-code listing
- Uncomment C/C++ source code that has been commented out
There are two ways to execute editing commands: by choosing commands from the Edit menu and by typing keyboard shortcuts. For details, see Using the Text Editor.
Editor Modes
The C/C++ editor, like the text editor, is always in one of two modes: edit mode or the default read-only mode. When the editor is in edit mode, you can modify files. When the editor is in read-only mode commands that modify files are inactive or grayed. To toggle between edit and read-only mode, select File > Edit or click the Edit button.
Searching for Text and Replacing Text
To search for text that matches a specified string in a source file, choose Search from the Edit menu or type keyboard shortcuts. You can also search for text and replace it with a different string. For details, see Selecting Text and Replacing Text.
Cutting and Pasting Text
To cut selected text from the C/C++ editor window and transfer it to an internal clipboard, choose the Cut command from the Edit menu. When text has been transferred from an Apex window to the clipboard, you can paste the text into windows displayed by other applications running under the Motif window manager. For more information on cutting and pasting text, see Editing Text.
To delete selected text from the edit window, choose Delete from the Edit menu or execute one of the keyboard shortcuts listed in Deleting Text from a Document.
C/C++-Specific EditingIn addition to its standard text-editing features, the Apex C/C++ editor offers many C/C++-specific editing features. You choose commands from the editor's Compile and Navigate menus to use these features.
C/C++ files are made up of objects such as keywords, identifiers, statements, and declarations. These objects are arranged in a hierarchical structure and are related to each other in various ways. The Apex C/C++ editor is designed to recognize the structure of C/C++ objects and the relationships that C/C++ objects have with each other, and to offer special browsing and selecting commands for C/C++ files.
Browsing
With the C/C++ editor, you can browse through interdependent C/C++ files in the same way you might browse through a printed cross-reference listing. However, with Apex, no listing is required; browsing is interactive and automatic. Browsing uses the dependency information and is useful, for example, when you are:
- Inspecting someone else's program and want to find type definitions for program variables.
- Debugging a problem and want to see where and how a particular function is implemented.
- Considering a change to a function and want to know exactly where that subprogram is used.
Traversing
To traverse C/C++ variables, classes, and functions, place the cursor on an object and select one of the following Visit or Visit In Place commands (for more information on the Visit or Visit In Place commands, see Using and Customizing the GUI).
- Navigate > Visit or Navigate > Visit In Place —— Traverses to the defining occurrence of a program object such as a function, variable, or type.
- Navigate > Visit C/C++ Name —— Opens a dialog box you can use to traverse to a C++ file, given its name.
- Navigate > Visit Body or Navigate > Visit Body In Place —— Traverses to the body of a C++ specification.
- Navigate > Other Part or Navigate > Visit Other Part In Place —— Traverses to the corresponding .h file from the .C or .c file. Traverses to the .C or .c file from the .h file.
For example, to traverse to the defining occurrence of a program object such as a function, variable, or type:
- 1 . Place the cursor on any occurrence of the object.
- 2 . Choose the Navigate > Visit command. (Visit is also available on the button bar and pop-up menu.)
Note that browsing operations depend on semantic information about your C/C++ files that is collected during semantic analysis. If you have difficulty browsing because you have made changes since the last time you analyzed a file, select Compile > Analyze and then try browsing again.
Viewing the Usage of C/C++ Objects
When you execute commands available from the Compile menu, you can find:
- All the places where a particular C/C++ object is used
- All C/C++ objects that are not used
The commands for viewing the usage of C/C++ objects are:
- Compile > Show Usage
- Compile > Local Usage
- Compile > Show Unused
By default, all three of the commands listed above display dialog boxes that let you specify C/C++ items. Alternatively, you can execute each of these three commands as a "just-do-it" menu command by holding down the Shift key while you choose the command you want to execute. (For more information on "just-do-it" menu items, see Using and Customizing the GUI.)
Table 15 lists the effects of executing the Show Usage, Local Usage, and Show Unused commands.
When you execute one of the commands listed in the above table, Apex highlights each occurrence it finds. You can then traverse from one occurrence to another by clicking the Message -> button or the Message <- button in the Apex editor's button bar.
If many files reference an object, Apex displays a window listing all such files. You can then visit each file in turn and click Message -> or Message <- to traverse between references.
C/C++-Specific Edit Commands
Several commands make the formatting and maintenance of C/C++ files easier and more convenient:
- Edit > Comment —— Adds two slashes to the beginning of selected lines to turn them into C/C++ comments. Edit > Uncomment removes the slashes.
- Compile > Import Text Files- Brings in text files containing C/C++ source code.
Error Checking
When you write C/C++ source code using the Apex C/C++ editor, you can check your C/C++ files for errors as you edit them. The Compile > Code menu command performs error checking.
When you execute the Code command, Apex displays any errors found in the Output window and in a Summary window. You can traverse from an error in the Summary window by double-clicking on the error message. In addition, you can select an error in the C/C++ editor that is highlighted and execute the Help > Explain command to display the corresponding error message.
Rational Software Corporation http://www.rational.com support@rational.com techpubs@rational.com Copyright © 1993-2002, Rational Software Corporation. All rights reserved. |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |