Skip to Main Content Skip to Search
Product Documentation

Pointers

Pointers for Signals

To create a pointer in the generated code, you can configure a signal to use the ImportedExternPointer storage class or use an mpt.Signal (or mpt.Parameter for parameters) object with an ImportedExternPointer storage class.

C Construct

extern double *u1;

Procedure

This is a quick method to obtain pointers in the generated code. You cannot control the data type, which is decided by the model compilation process.

  1. Create the ex_pointer_signal model using the blocks shown and follow the steps to configure the signals and model.

  2. Label the signal to be imported as a pointer, in this example, u1.

  3. Right-click the u1 signal line and select Signal Properties.

  4. Select the Code Generation tab and specify the Storage Class parameter as ImportedExternPointer.

  5. Click OK.

  6. Press Ctrl+B to generate code.

Results

The generated code includes the extern declaration for the pointer in the ex_pointer_signal_private.h file.

extern real_T *u1;

Pointers for Signals and Parameters Using Simulink Data Objects

C Construct

extern double *u1;

Procedure

You can control the data type by using a Simulink data object to generate a pointer. You can use this procedure for either a signal or parameter. To create a pointer for a parameter, use an mpt.Parameter instead of an mpt.Signal data object described in step 3.

  1. Create the ex_pointer_signal_data_object model using the blocks shown and follow the steps to configure the signals and model.

  2. Label the signal to be imported as a pointer, in this example, u1.

  3. At the MATLAB command line, create a data object for signal u1.

    u1 = mpt.Signal;
  4. In the base workspace, double-click u1 to open the mpt.Signal dialog box.

  5. Specify the Storage class parameter as ImportedExternPointer.

  6. Click Apply and OK.

  7. Press Ctrl+B to generate code.

Results

The generated code includes the extern declaration for the pointer in the ex_pointer_signal_data_object_private.h file.

extern real_T *u1;

The ex_pointer_signal_data_object_private.h file imports the pointer into the generated code. To compile the code, you must declare and define the pointer in the main program.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS