LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't generate function tree - typedef enum error

Hello,

 

I’m trying to generate a function tree from a header file but I'm getting an “Unknown data type” error in a function declaration taking a typedefed parameter.  Please let me know what I’m doing wrong.

 

typedef enum

{

            FIRST,

            SECOND

}MY_ENUM;

 

/// ENUM MY_ENUM

            #define FIRST

            #define SECOND

 

int  dllexport __cdecl myFunc( int param1, MY_ENUM param2);

 

 

Thanks for any help or suggestions,

Joe

 

 

0 Kudos
Message 1 of 8
(4,468 Views)
Howdy Joe,

You need the // comment specifier after each enum value for the label. Try this.

typedef enum

{

            FIRST,       // FIRST

            SECOND   // SECOND

} MY_ENUM;

 

/// ENUM MY_ENUM
#define FIRST

#define SECOND

 

int  dllexport __cdecl myFunc( int param1, MY_ENUM param2);


Let me know if this doesn't work for you. Using enums in header files can be a littel tricky. I would check out Generate Function Tree CVI Help (Help >> Contents; Switch to the Index tab and type "Generate Function Tree") to see the rules for header files.


Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 2 of 8
(4,455 Views)
Hi Jonathan,

I'll give your suggestion a try, but I thought the comment specifier is supposed to go with the #define.  I have that in my actual code but I left it out of the example because I thought it was optional.  I have the function tree help open - I used it as my guideline to get this far.

I guess I could try generating the function tree from scratch in the F.T. editor, but then I'm afraid I'll just run into the "unknown data type" problem all over again.


Please let me know if you think of anything else.

Thanks,
Joe

0 Kudos
Message 3 of 8
(4,450 Views)
Hi Joe,

You have a couple of options depending upon how you set up your header file. For example, you could do

typedef enum
{
    FIRST,     // myFirst
    SECOND     // mySecond

} MY_ENUM;

int dllexport __cdecl myFunc( int param1, MY_ENUM param2);


The above code would result in the attached "Function Panel 1.jpg" snapshot.

You could also do something like:

/// ENUM MY_ENUM
#define FIRST
#define SECOND

/// BIN 2/MY_ENUM

int dllexport __cdecl myFunc( int param1, int param2);

This would generate a function panel like the attached "Function Panel 2.jpg" snapshot. When you use this method, notice you don't need the comments after the #defines. The first method you need those comments to serve as value labels. Otherwise you would get some error mentioning that the number of values and labels in the enum didn't match. 

If found a good post also to look at. In the post there is an example header file which shows a bunch of different ways of using the specifiers. I will also attach it here as well.

Anyway, this should get you up and running!

Best Regards,
Jonathan N.
National Instruments
Download All
0 Kudos
Message 4 of 8
(4,431 Views)

Hello again Jonathan,

I finally got back to this and tried again.  I was still getting "unknown data type" at the function declaration that takes the enum parameter, until I changed this:

typedef enum
{
    FIRST,     // myFirst
    SECOND     // mySecond
}
MY_ENUM;

to this:

typedef enum
{
    FIRST,     // myFirst
    SECOND     // mySecond
} MY_ENUM;
 ^

Apparently the Function Tree tool is extremely finicky about placement of white space.  It also chokes on "int* my_int_ptr", which has to be "int *my_int_ptr".

Now I'm trying to figure out how to format a function declaration that takes a pointer to a function as a parameter.  I've tried every placement of white space I can think of and am still getting "The parameter type is not a valid identifier", e.g.:

int my_func( int ( *func_ptr)( int *));

Thanks,
JoeN

0 Kudos
Message 5 of 8
(4,385 Views)
Hi Joe,

There are very strict rules on formatting and whitespace when generating function trees. When in doubt, please refer to the documentation under the CVI help section:
Using LabWindows/CVI » Writing Source Code » Generating a Function Tree from an Include File

I was able to generate a function tree from both version of the enum you have above, and the result you saw with the pointer parameter is expected behavior per the help section:
"If you have a pointer in a function declaration, make sure that the asterisk is immediately next to the parameter name, with no white space in between. For example, use datatype *parameter."

I am still looking into using function pointer parameters, but for now, I suggest you use:
int my_func(void *functionPtr, void *functionData);

Regards,
0 Kudos
Message 6 of 8
(4,330 Views)

Hi James,

Thanks very much for your help.

FWIW, I'm using LW/CVI version 7.1.1, and that statement isn't in my version of Help at the place you cited.  There is only one mention of white space, ("LabWindows/CVI preserves white space from the header file to the generated header file"), and no instance of the word "asterisk".

Maybe someday my employer will spring for the latest version Smiley Tongue

I worked around the pointer-to-function issue by putting the args in a struct and passing that.

Thanks again,
JoeN

0 Kudos
Message 7 of 8
(4,323 Views)

Hi Joe,

We added more information about rules for using the Generate Function Tree command in LabWindows/CVI 8.0.  Therefore you wouldn't have that text snippet that James mentioned in the help.

To address your question, you need to do several things. First off you need to make sure that you have defined your function pointer prototype in your header file prior to using it. Secondly, you need to use the /// ADDT tag to add your "function pointer" type to the function panel. If you don't use this tag, you would get an error like "unknown data type". So you would say something like

// Define your function pointer prototype
typedef int (*func_ptr)(int *);
                   
/// ADDT func_ptr

// using the type
int DLLEXPORT my_func(func_ptr value);

Hope this helps!

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 8 of 8
(4,310 Views)