We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How do functions evaluate arguments?

Roni
Roni asked
on
Medium Priority
884 Views
Last Modified: 2009-07-29
I just want to know if I am on the right path.  The function will evaluate an argument like an error check?  Say for instance, if you are suppose to have numeric - it will evaluate the input whether it is numeric or alpha?  I am very confused with this.  I am just a beginner in C++, taking a class thorugh work and they did not have such good explainations on this subject enough for me to understand it.
Comment
Watch Question

Senior Software Engineer
Commented:
The argument is evaluated at compile time, and if it does not match the function arugment type, or can not be converted via operators, than you'll get a compile error.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Can you give me an example?  I am still not understanding - so you are saying it does work like an error handler?
jkr
CERTIFIED EXPERT
Top Expert 2012
Commented:
Basically, Axter is correct - however, just about the syntax. The is no logical evaluation, so you still could break functionality by passing nonsense values like e.g.

int Add(int a, int b) {

    return a + b;
}

Add((int) "one", (int) "two");

or

char arr[255] = "test";

strcat(test,(char*) 42);
AxterSenior Software Engineer

Commented:
>>so you are saying it does work like an error handler?

At compile time, yes.
But that's if you don't use explicit casting, as in jkr's example.

In general, you should avoid casting, because you're removing the compiler's ability to catch errors at compile time.

Author

Commented:
Thank you very much.  In reading your explainations and researching more, I now understand......thank you both again....

Author

Commented:
Okay....how do I change it?  

Author

Commented:
Thank you.....
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.