Example Code

LabWindows/CVI - Function Overloading

Code and Documents

Attachment

Overview

Function overloading is common in object oriented languages. It allows the same function name to work with varied datatypes, and implement different functionality. The LabWindows/CVI compiler has a number of extensions to ANCI C, one of which is function overloading. This simple example demonstrates how to implement it. 

 

Description

The example calls a function, add2numbers, three times. On each call the function is passed two numeric data parameters of a different type (float, double, integer), that it adds together, and returns the result.

 

Hardware and Software Requirements

 

No hardware is used in this example.

 

Steps to Implement or Execute Code

 

  1. Download the attached zip file (Function Oveload.zip).
  2. Extract the five files contained in the zip file to a folder.
  3. Navigate to the folder with the extracted files and open the 'Function Overloading.prj'.in LabWindows/CVI. 
  4. In the project open the Window>>Debug Output window to view the results of the addition.
  5. Build and run the code, and view the results in the Debug Output window.
  6. Examine both the 'Function Overloading.c' and 'Function Overloading.h' files to see how the function add2number() is declared and defined for each datatype.

 

Additional Information or References

There is further information in the LabWindows/CVI help, section: Programmer Reference>>LabWindows/CVI Compiler Overview>>C Language Extensions

 

 

David C

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors