This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

func and func()

Hi All,

let a function prototype is :

bit func();

Now if it is used as follows (inadvertently) then what would it do ?? Why not the complier throws an error ??

if (func) {
...
...
}
else {
...
...
}

-Rocknmoon()

Parents
  • There is nothing wrong with what you did. You are checking to see if func is a null pointer or not, it isn't. The compiler could warn that your if clause is always constant but maybe you don't have the warning level up. Or maybe you forgot to run you code through Lint, but who would do that, eh?

    By the way, excluding the (void) in your prototype means that the compiler will use the first occurance of the function's usage as the true prototype. This is not C++ so to be strictly proper you should define and prototype the function identically, e.g.

    bit func(void) { return bitVar }
    and
    bit func(void);

Reply
  • There is nothing wrong with what you did. You are checking to see if func is a null pointer or not, it isn't. The compiler could warn that your if clause is always constant but maybe you don't have the warning level up. Or maybe you forgot to run you code through Lint, but who would do that, eh?

    By the way, excluding the (void) in your prototype means that the compiler will use the first occurance of the function's usage as the true prototype. This is not C++ so to be strictly proper you should define and prototype the function identically, e.g.

    bit func(void) { return bitVar }
    and
    bit func(void);

Children
No data