invalid operands to binary == or wrong type argument to unary exclamation mark

S

Sheldon

Hi Everyone,

I have defined a function:

struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct
Transient retv);

and in the code:

struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct
Transient retv) {

snip

if(hdfdata != NULL) free(hdfdata);
return retv;
fail:
if(hdfdata != NULL) free(hdfdata);
exit(EXIT_FAILURE);
}

called the function like this:

if (arrFromHdfNode(nodelist,retv) == NULL) {
fprintf(stderr,"Failed getting data\n");
goto fail;

or like this

if (!(arrFromHdfNode(nodelist,retv))) {
fprintf(stderr,"Failed getting data\n");
goto fail;

The functions should return a struct or exit(EXIT_FAILURE) if
something went wrong.

For the first call I got the error:
error: invalid operands to binary ==
and for the second I got:
error: wrong type argument to unary exclamation mark

Can someone point me in the right direction? What is going on here?

Thanks in advance,
/S
 
S

santosh

Hi Everyone,

I have defined a function:

struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct
Transient retv);

and in the code:

struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct
Transient retv) {

snip

if(hdfdata != NULL) free(hdfdata);
return retv;
fail:
if(hdfdata != NULL) free(hdfdata);
exit(EXIT_FAILURE);
}

called the function like this:

if (arrFromHdfNode(nodelist,retv) == NULL) {
fprintf(stderr,"Failed getting data\n");
goto fail;

or like this

if (!(arrFromHdfNode(nodelist,retv))) {
fprintf(stderr,"Failed getting data\n");
goto fail;

The functions should return a struct or exit(EXIT_FAILURE) if
something went wrong.

For the first call I got the error:
error: invalid operands to binary ==
and for the second I got:
error: wrong type argument to unary exclamation mark

Can someone point me in the right direction? What is going on here?

The function is defined as returning a struct Transient type object.
NULL is a pointer constant value. Both are not directly comparable. One
possibility is for the function to return a pointer to struct Transient
and return a null pointer value on error.

Similarly the ! operand accepts only a scalar type. A struct object is
not a scalar type. Again returning a pointer to that struct type would
solve this problem.
 
S

Sheldon

Sheldon said:










That's an unconditional return, and you're not in a loop or anything like
that. So everything from here to the end of that function is unreachable
code.


You don't use this.




But arrFromHdfNode returns a struct, not a pointer. C doesn't allow you to
use the == operator to compare structs, so you can't have a struct as one
of the operands, and the value returned by arrFromHdfNode(nodelist, retv)
has struct type, and that's why you're getting your error.


You're trying to use goto to jump from one function to a label in another
function. Again, this is against the rules of C.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999- Dölj citerad text -

- Visa citerad text -

Thanks! Will redo the code accordingly.

/S
 
S

Sheldon

The function is defined as returning a struct Transient type object.
NULL is a pointer constant value. Both are not directly comparable. One
possibility is for the function to return a pointer to struct Transient
and return a null pointer value on error.

Similarly the ! operand accepts only a scalar type. A struct object is
not a scalar type. Again returning a pointer to that struct type would
solve this problem.- Dölj citerad text -

- Visa citerad text -

Thanks! Will redo the code accordingly.

/S
 
R

Richard Heathfield

Sheldon said:
Hi Everyone,

I have defined a function:

struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct
Transient retv);

and in the code:

struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct
Transient retv) {

snip

if(hdfdata != NULL) free(hdfdata);
return retv;

That's an unconditional return, and you're not in a loop or anything like
that. So everything from here to the end of that function is unreachable
code.

You don't use this.
if(hdfdata != NULL) free(hdfdata);
exit(EXIT_FAILURE);
}

called the function like this:

if (arrFromHdfNode(nodelist,retv) == NULL) {

But arrFromHdfNode returns a struct, not a pointer. C doesn't allow you to
use the == operator to compare structs, so you can't have a struct as one
of the operands, and the value returned by arrFromHdfNode(nodelist, retv)
has struct type, and that's why you're getting your error.
fprintf(stderr,"Failed getting data\n");
goto fail;

You're trying to use goto to jump from one function to a label in another
function. Again, this is against the rules of C.
 
W

Willem

Richard wrote:
) Sheldon said:
)> snip
)>
)> if(hdfdata != NULL) free(hdfdata);
)> return retv;
)
) That's an unconditional return, and you're not in a loop or anything like
) that. So everything from here to the end of that function is unreachable
) code.
)
)> fail:
)
) You don't use this.

Isn't that right there a label you can goto ?

)> if(hdfdata != NULL) free(hdfdata);
)> exit(EXIT_FAILURE);
)> }


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top