NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Active Participant
jspaarg
Posts: 219
0 Kudos

Possible Bug in Function Call

I believe that there may be a problem in the compiler syntax checker.

I accidentally typed this for a function call and the complier did not flag an error.

It compiled cleanly, but reported an incorrect value.

 

Here is the goof.  Notice the comma between the function name and the left parenthesis.

 

 GetCtrlVal,(HeaterPanelHandle,HEATER_LASTPOINTS, &points);

 

It seems that the complier should complain about this as it is not correct syntax.

 

Thanks

Jacob

 


 

Member
JD_war_eagle
Posts: 126
0 Kudos

Re: Possible Bug in Function Call

Hi jspaarg,

 

Thank you for bringing this to our attention.  I agree that the compiler should be presenting and error in this case, and I will make our R&D colleagues aware of this issue.

Justin D
Applications Engineer
National Instruments
http://www.ni.com/support/
Active Participant
LuisG
Posts: 1,807
0 Kudos

Re: Possible Bug in Function Call

Although non-sensical, that's actually a legal expression. It's perfectly legal to have a C statement consisting of a single identifier, or a single expression. For example:

 

1;

 

or:

 

1+1;

 

or:

 


int a;

a;

 

Note also that GetCtrlVal is also an expression in C. It's a function pointer that can be assigned to a function pointer variable, for example. Therefore, this is also legal:

 

GetCtrlVal;

 

In C, you can add as many commas between statements as you like. It imposes an order of evaluation of the comma-separated items. See here for more information. Therefore, this is also valid:

 

GetCtrlVal,1;

 

Finally, you can always add parentheses around any operands, which is why this is also valid:

 

GetCtrlVal,(1,1,a);

 

Luis




Active Participant
tstanley
Posts: 296
0 Kudos

Re: Possible Bug in Function Call

I've noticed that the compiler will throw a warning (Missing argument list for call to function) if you do this:

 

GetCtrlVal;

 

 However, it is silent if you do this:

GetCtrlVal,1;

 

 Any reason for this or is this just something that was overlooked?

Active Participant
LuisG
Posts: 1,807
0 Kudos

Re: Possible Bug in Function Call

That warning is probably a legacy of when the C syntax was considered a significant departure from Pascal that it could conceivably trip up programmers unaccustomed to the C syntax. (Pascal allows zero-argument functions to be called without an argument list).

 

This warning is only displayed for simple, single-identifier expressions, which is the only situation in which you might conceivably mean intend to call the function while inadvertently leaving  out the argument list. But when you add a comma to the expression, you no longer have a simple expression. Instead you have a sequence of two expressions: the function identifier and something else.

 

You also don't get the warning if your statement is myFunc = GetCtrlVal; since your intention in this case is to use the function name as a constant expression, not as a function call.

 

Luis

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page