By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Nov 6 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Tuesday 06 Nov 2007 3:45 pm Sheldon <sh******@gmail.comwrote in
article <11**********************@o38g2000hse.googlegroups .com>:
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.

Nov 6 '07 #2

P: n/a
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.
fail:
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.
--
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
Nov 6 '07 #3

P: n/a
On 6 Nov, 11:25, Richard Heathfield <r...@see.sig.invalidwrote:
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.
fail:

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 asone
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.

--
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

Nov 6 '07 #4

P: n/a
On 6 Nov, 11:22, santosh <santosh....@gmail.comwrote:
On Tuesday 06 Nov 2007 3:45 pm Sheldon <shejo...@gmail.comwrote in
article <1194344102.049441.174...@o38g2000hse.googlegroups .com>:


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.- Dölj citerad text -

- Visa citerad text -
Thanks! Will redo the code accordingly.

/S

Nov 6 '07 #5

P: n/a
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
Nov 6 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.