cannot get the right address/pointer

D

DanielJohnson

I have two structs as follows:

struct i_args{
struct connector *connects;
size_t num;
};

struct connector{
struct sockaddr_storage addr;
int array_num;
}

Now I have a function whose prototype is as follows:

int some_function(const struct sockaddr_storage *);

Now I have some variable using above structs as follows:

struct i_args *args;
args->num = 5;
int i = 0;
for (i = 0; i< 5;i++){
if ( !some_func(&args->connects.addr) { /* I get a warning
on this line) */
....
....
}
}


When I make a function call some_func(&args->connects.addr), I get
an error "
warning: passing arg 1 of `some_func' from incompatible pointer
type".

I can't figure out why. Can anybody point me as to where am I going
wrong.

Thanks
 
K

Keith Thompson

DanielJohnson said:
I have two structs as follows:

struct i_args{
struct connector *connects;
size_t num;
};

struct connector{
struct sockaddr_storage addr;
int array_num;
}

Now I have a function whose prototype is as follows:

int some_function(const struct sockaddr_storage *);

Now I have some variable using above structs as follows:

struct i_args *args;
args->num = 5;
int i = 0;
for (i = 0; i< 5;i++){
if ( !some_func(&args->connects.addr) { /* I get a warning
on this line) */
....
....
}
}


When I make a function call some_func(&args->connects.addr), I get
an error "
warning: passing arg 1 of `some_func' from incompatible pointer
type".

I can't figure out why. Can anybody point me as to where am I going
wrong.


When I copied the code you posted into a small program, fixed some
typos, and compiled it, I didn't get any diagnostics; when I cranked
up the warning level, I got a few warnings about using uninitialized
variables.

Note that you have a missing ';' on the declaration of struct
connector, and you've spelled your function name both as
"some_function" and as "some_func".

The problem is in the actual code that you compiled, not in the code
that you posted. Since we can only see the latter, there's not much we
can do to help.

Unless, of course, you can construct a small complete program (or at
least a translation unit) that exhibits the problem, and
copy-and-paste the *exact* source file.

It's likely that in the process of narrowing down your code to a small
postable example, you'll figure out the problem yourself. If not,
feel free to post.
 
D

DanielJohnson

It's likely that in the process of narrowing down your code to a small
postable example, you'll figure out the problem yourself.  If not,
feel free to post.

I am actually trying to understand the warning I got "warning: passing
arg 1 of `some_func' from incompatible pointer
type". Even though I made few typos on the code I posted, my code
looks fine in the file here.

Do you think that I am using pointer of incompatible type ? ( I think
that I am not but the compiler gcc version 3.4.4 [FreeBSD] 20050518)
thinks that I am.)

Any comments ?
 
K

Keith Thompson

I wrote the above. When you post a followup, please leave the
attribution lines alone (such as the line "DanielJohnson
arg 1 of `some_func' from incompatible pointer
type". Even though I made few typos on the code I posted, my code
looks fine in the file here.

It may look fine to you, but it obviously doesn't look fine to your
compiler. In the absence of any evidence, I'm going to bet that it's
the compiler that got it right. Note that your compiler, unlike the
rest of us, has the benifit of seeing your actual code.
Do you think that I am using pointer of incompatible type ? ( I think
that I am not but the compiler gcc version 3.4.4 [FreeBSD] 20050518)
thinks that I am.)

Yes, I do -- but without seeing your *actual code* (copy-and-pasted,
not re-typed)I can't be 100% sure, and neither I nor anyone else can
help you.
 
N

Nick Keighley

It's likely that in the process of narrowing down your code to a small
postable example, you'll figure out the problem yourself.  If not,
feel free to post.

I am actually trying to understand the warning I got "warning: passing
arg 1 of `some_func' from incompatible pointer
type". Even though I made few typos on the code I posted, my code
looks fine in the file here.

Do you think that I am using pointer of incompatible type ?
yes

( I think
that I am not but the compiler gcc version 3.4.4 [FreeBSD] 20050518)
thinks that I am.)

Any comments ?
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top