473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
5 7093
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Guy | last post by:
I'd like so that when a user moves there mouse over an image (or clicks the image, either way it doesn't matter), I'd like some text to appear. I was going to use the img tag with the alt...
2
by: DraguVaso | last post by:
Hi, I have a DataGrid bound to an sqlDataAdapter. When I do a SqlDataAdapter.Update, on 1 row I got a red dot with a whie exclamation mark in it, to show me there is an error, and the changes...
4
by: muthu | last post by:
In the following code it gives the error "error: invalid operands to binary &" Why it is happening #include <signal.h> #include <errno.h> #define SIGBAD(signo) ((signo) <= 0 || (signo) >=...
1
by: Richard Eich | last post by:
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3) source snippet: .... int i = 17 ; if ( 0x03 & i ) ....
11
by: Spiros Bousbouras | last post by:
#include <stdlib.h> int main(void) { char **p1 ; const char **p2 ; p1 = malloc(5 * sizeof(char *)) ; if (p1 == 0) return EXIT_FAILURE ; p2 = p1 + 1 ; p2 - p1 ;
2
by: xelloss | last post by:
#include<cstdlib> #include<iostream> #include<iomanip> #include<vector> #include<fstream> using namespace std; double sum(vector<double> x) { double total = 0.0;
1
by: =?Utf-8?B?VE1D?= | last post by:
Hello, I am running XP with windows firewall, I can sign in to WLM with no problem but cannot contact any contacts or send emails. It say's there offline and tells them I am offline. I can receive...
2
by: Tyler Palmer | last post by:
I am having a problem with my program. I cant figure out a solution for the compiler error im getting. In function `double endingConversion(double)': invalid operands of types `double...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.