question is:

Give 5 type checks that should be made for the following c++ statement:

x=f(v[i]);

NOTE: assume x, f,v and i are all declared and in scope.

  1. compatibility check (compile time)
  2. v[i] is a valid array element. (compile time) (i.e. (i is not a float or something))
  3. bounds checking for the array v[i]
  4. ?
  5. ?

NOt sure what other checks I would be able to do? Seems like all possible. any help is greatly appreciated. Thanks.

  1. the names x, v, f and i can be unambiguously resolved by name look-up; except that f may be the name of a function with two or more unambiguous overloads.

  2. v is either a pointer (other than pointer to possibly cv-qualified void) or an object which has an overloaded subscript operator.

  3. i is of a type trivially or impliciltly convertible to the type of the subscript required by v[]

  4. If x=f(v[i]); does not appear at class scope, f is a free function which can be invoked with one argument (either a unary function or with default values for the other arguments) or a pointer or a reference to a unary function, or a unary function object

  5. If x=f(v[i]); appears at class scope, f may also be a member function callable with one explicit argument.

  6. the result type of v[i] is trivially or impliciltly convertible to the type of the argument required by f

  7. if f is the name of an overloaded function, or an overloaded function call operator, the overload to be called for f(v[i]) can be unambiguosly resolved

  8. x is a non-const lvalue, or an lvalue reference or rvalue reference to a non-const object

  9. x is an object of, or a reference to an object of an assignable type

  10. the result type of f(v[i]) is trivially or impliciltly convertible to the type of an object that can be assigned to x

This is probably not exhaustive; I'd be surprised if there weren't some cases that were missed.

commented: good effort! +13

Your question isn't clear. Can you post your question once more, with more details and the pin point the problem you are having

Check that all of the variables have been initalized before use.

vijayan121 thanks. That makes sense, aprreciate it.
np complete that is the entire question. It was dealing with type checks needed to be made on that particular assignment statement with the conditions we assumed. My issue was that I did not know what other types of checks I ( c++ compiler) would have to make when this assignment is actually done. But I think I got it now. Thanks anyway.

Give 5 type checks

...

My issue was that I did not know what other types of checks

There is a huge difference between saying "type checks" and "types of checks". The answer vijayan121 gave was specifically referring to "type checks", in other words, a set of conditions that the compiler must verify about the declarations (types) of the variables (identifiers) involved in the expression given. This is how I originally understood the question too. If you are talking about "types of checks", then it is a very different question, with a very different list. Vijayan121's comprehensive answer really just involves two types of checks that the compiler does: type checking and overload resolution (or argument-dependent lookup). But as a programmer, there are many more things you can verify to ensure the statement in question is correct (including a range check, that there is no involuntary implicit conversion happening, re-entrance, making sure f() does not store or return a pointer / reference to a by-const-reference parameter, etc.).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.