Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > invalid operands to binary == or wrong type argument to unary exclamation mark

Reply
Thread Tools

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

 
 
Sheldon
Guest
Posts: n/a
 
      11-06-2007
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

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      11-06-2007
On Tuesday 06 Nov 2007 3:45 pm Sheldon <(E-Mail Removed)> wrote in
article <(E-Mail Removed) .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.

 
Reply With Quote
 
 
 
 
Sheldon
Guest
Posts: n/a
 
      11-06-2007
On 6 Nov, 11:25, Richard Heathfield <(E-Mail Removed)> wrote:
> 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- Dölj citerad text -
>
> - Visa citerad text -


Thanks! Will redo the code accordingly.

/S

 
Reply With Quote
 
Sheldon
Guest
Posts: n/a
 
      11-06-2007
On 6 Nov, 11:22, santosh <(E-Mail Removed)> wrote:
> On Tuesday 06 Nov 2007 3:45 pm Sheldon <(E-Mail Removed)> wrote in
> article <(E-Mail Removed) .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

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      11-06-2007
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
 
Reply With Quote
 
Willem
Guest
Posts: n/a
 
      11-06-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is cast operator unary or binary? How many operands? JoseMariaSola C Programming 16 05-12-2008 07:41 AM
Invalid operands to binary - Spiros Bousbouras C Programming 11 08-08-2007 10:17 PM
[?] invalid operands to binary & Richard Eich C Programming 1 02-05-2007 09:09 AM
error: invalid operands to binary & muthu C Programming 4 07-17-2006 08:52 PM
Ordinary unary function to STL adaptable unary predicate how? SpOiLeR C++ 10 10-19-2005 01:18 PM



Advertisments