Need help with these function variable pointers? 
Author Message
 Need help with these function variable pointers?

Hi,

I'm trying to to get my VREC_STRUCT script and programlist_struc rec, **pi
to make them point to the
incomming function arguments. I'm getting error C2115: '=' : incompatible
types on all the variables script,rec,pi below.

What could I be doing wrong. I'm a newbie at this.

VREC_STRUCT script;
programlist_struct rec, **pi=NULL;

int GetProgramIds(VREC_STRUCT *_script,programlist_struct *_rec,
programlist_struct **_pi){

 TEXT  t1[26];
 COUNT i=0;

 script  = _script;
 rec    =   _rec;
 pi      =   _pi;

..... code continues using those datatypes above

return 0;

Quote:
}

Your help is really appreciated.
Thanks,
jt


Mon, 27 Dec 2004 06:23:05 GMT  
 Need help with these function variable pointers?

Quote:
> Hi,
> I'm trying to to get my VREC_STRUCT script and programlist_struc rec, **pi
> to make them point to the
> incomming function arguments. I'm getting error C2115: '=' : incompatible
> types on all the variables script,rec,pi below.
> What could I be doing wrong. I'm a newbie at this.
> VREC_STRUCT script;
> programlist_struct rec, **pi=NULL;
> int GetProgramIds(VREC_STRUCT *_script,programlist_struct *_rec,
> programlist_struct **_pi){
>  TEXT  t1[26];
>  COUNT i=0;
>  script  = _script;

script is a variable of type VREC_STRUCT (whatever this is supposed to
be), _script is a *pointer* to a a variable of type VREC_STRUCT, they
are as different as an integer and a pointer to an integer - so what
do you expect except the compiler telling you so?

By the way, don't use variable names starting with an underscore, they
are reserved and shouldn't be used by 'normal' programs.

Quote:
>  rec    =   _rec;

Same here...

Quote:
>  pi      =   _pi;

This should be ok, are you sure the compiler is really complaing about
this line?

But if you want script to point to the first argument of your function
you would need

VREC_STRUCT **script;           /* Pointer to VREC_STRUCT * type var */

...

script = &_script;
                                      Regards, Jens
--
      _  _____  _____

  _  | |  | |    | |          AG Moebius, Institut fuer Molekuelphysik
 | |_| |  | |    | |          Fachbereich Physik, Freie Universitaet Berlin
  \___/ens|_|homs|_|oerring   Tel: ++49 (0)30 838 - 53394 / FAX: - 56046



Mon, 27 Dec 2004 08:04:27 GMT  
 Need help with these function variable pointers?

Quote:

>Hi,

>I'm trying to to get my VREC_STRUCT script and programlist_struc rec, **pi
>to make them point to the
>incomming function arguments. I'm getting error C2115: '=' : incompatible
>types on all the variables script,rec,pi below.

>What could I be doing wrong. I'm a newbie at this.

>VREC_STRUCT script;
>programlist_struct rec, **pi=NULL;

>int GetProgramIds(VREC_STRUCT *_script,programlist_struct *_rec,
>programlist_struct **_pi){

You should not be using names that begin with an underscored since
they are reserved for the implementation.

Quote:

> TEXT  t1[26];
> COUNT i=0;

> script  = _script;

script is defined as a VREC_STRUCT.  _script is defined as a
VREC_STRUCT*.  You cannot assign The address of an object to a pointer
to that object (except if the object has type void*).

Quote:
> rec    =   _rec;

Same problems with rec and _rec.

Quote:
> pi      =   _pi;

This one is correct.

Quote:

>..... code continues using those datatypes above

>return 0;

>}

<<Remove the del for email>>


Mon, 27 Dec 2004 08:25:26 GMT  
 Need help with these function variable pointers?


Quote:

> >Hi,

> >I'm trying to to get my VREC_STRUCT script and programlist_struc rec, **pi
> >to make them point to the
> >incomming function arguments. I'm getting error C2115: '=' : incompatible
> >types on all the variables script,rec,pi below.

> >What could I be doing wrong. I'm a newbie at this.

> >VREC_STRUCT script;
> >programlist_struct rec, **pi=NULL;

> >int GetProgramIds(VREC_STRUCT *_script,programlist_struct *_rec,
> >programlist_struct **_pi){

> You should not be using names that begin with an underscored since
> they are reserved for the implementation.

Two people saying that in a row - it's not quite right. Names beginning with
an underscore (other than those beginning with two underscores, or an
underscore followed by a capital letter) are only reserved as file scope
identifiers. You are allowed to use them inside a function, as he is doing.

--
Kevin Bracey
http://www.bracey-griffith.freeserve.co.uk/



Mon, 27 Dec 2004 14:44:19 GMT  
 Need help with these function variable pointers?


Quote:



> > >Hi,

> > >I'm trying to to get my VREC_STRUCT script and programlist_struc rec,
**pi
> > >to make them point to the
> > >incomming function arguments. I'm getting error C2115: '=' :
incompatible
> > >types on all the variables script,rec,pi below.

> > >What could I be doing wrong. I'm a newbie at this.

> > >VREC_STRUCT script;
> > >programlist_struct rec, **pi=NULL;

> > >int GetProgramIds(VREC_STRUCT *_script,programlist_struct *_rec,
> > >programlist_struct **_pi){

> > You should not be using names that begin with an underscored since
> > they are reserved for the implementation.

> Two people saying that in a row - it's not quite right. Names beginning
with
> an underscore (other than those beginning with two underscores, or an
> underscore followed by a capital letter) are only reserved as file scope
> identifiers. You are allowed to use them inside a function, as he is
doing.

> --
> Kevin Bracey
> http://www.bracey-griffith.freeserve.co.uk/

Sorry to say, but the underscore is not my problem. Taken underscore out
still the same problem.
All I need is some help to my question on making the local variable point to
the function arguments.

jt



Tue, 28 Dec 2004 08:32:18 GMT  
 Need help with these function variable pointers?

Quote:





>> > >I'm trying to to get my VREC_STRUCT script and programlist_struc rec,
> **pi
>> > >to make them point to the
>> > >incomming function arguments. I'm getting error C2115: '=' :
> incompatible
>> > >types on all the variables script,rec,pi below.

>> > >What could I be doing wrong. I'm a newbie at this.

>> > >VREC_STRUCT script;
>> > >programlist_struct rec, **pi=NULL;

>> > >int GetProgramIds(VREC_STRUCT *_script,programlist_struct *_rec,
>> > >programlist_struct **_pi){

>> > You should not be using names that begin with an underscored since
>> > they are reserved for the implementation.

>> Two people saying that in a row - it's not quite right. Names beginning
> with
>> an underscore (other than those beginning with two underscores, or an
>> underscore followed by a capital letter) are only reserved as file scope
>> identifiers. You are allowed to use them inside a function, as he is
> doing.
> Sorry to say, but the underscore is not my problem. Taken underscore out
> still the same problem.
> All I need is some help to my question on making the local variable point to
> the function arguments.

Your first argument is of type VREC_STRUCT *, so a variable *pointing* to
it must be of type VREC_STRUCT **. But your variable 'script' is of type
VREC_STRUCT, so you can't store in it the address of a pointer to such a
structure. You have to define 'script' as

VREC_STRUCT ** script;

to be able to say

script = & _script;

The & operator is needed to get the address of '_script' because you write
that you want to make the local variables point to the functions arguments.

The same holds for the next function argument. It's of type
programlist_struct *, so the type of a variable to store a pointer to it
needs to be programlist_struct **. Thus you will habe to define 'rec' as

programlist_struct ** rec;

and assign the address of the second function argument by using

rec = & _rec;

I don't understand why you want to do this but if you need to do exactly
what you're writing that's the way to go. But I suspect you actually want
to do something different, e.g. make copies of the structure to which
you pass pointers to the function. In this case your variable definitions
would be ok, but then you would have to write e.g.

script = * _script;
rec = * _rec;

(using that whole structures can be copied by assignment and assuming that
VREC_STRUCT and programlist_struct actually are typedef'ed structures...).

                                       Regards, Jens
--
      _  _____  _____

  _  | |  | |    | |          AG Moebius, Institut fuer Molekuelphysik
 | |_| |  | |    | |          Fachbereich Physik, Freie Universitaet Berlin
  \___/ens|_|homs|_|oerring   Tel: ++49 (0)30 838 - 53394 / FAX: - 56046



Tue, 28 Dec 2004 09:26:03 GMT  
 Need help with these function variable pointers?


Quote:






> >> > >I'm trying to to get my VREC_STRUCT script and programlist_struc
rec,
> > **pi
> >> > >to make them point to the
> >> > >incomming function arguments. I'm getting error C2115: '=' :
> > incompatible
> >> > >types on all the variables script,rec,pi below.

> >> > >What could I be doing wrong. I'm a newbie at this.

> >> > >VREC_STRUCT script;
> >> > >programlist_struct rec, **pi=NULL;

> >> > >int GetProgramIds(VREC_STRUCT *_script,programlist_struct *_rec,
> >> > >programlist_struct **_pi){

> >> > You should not be using names that begin with an underscored since
> >> > they are reserved for the implementation.

> >> Two people saying that in a row - it's not quite right. Names beginning
> > with
> >> an underscore (other than those beginning with two underscores, or an
> >> underscore followed by a capital letter) are only reserved as file
scope
> >> identifiers. You are allowed to use them inside a function, as he is
> > doing.

> > Sorry to say, but the underscore is not my problem. Taken underscore out
> > still the same problem.
> > All I need is some help to my question on making the local variable
point to
> > the function arguments.

> Your first argument is of type VREC_STRUCT *, so a variable *pointing* to
> it must be of type VREC_STRUCT **. But your variable 'script' is of type
> VREC_STRUCT, so you can't store in it the address of a pointer to such a
> structure. You have to define 'script' as

> VREC_STRUCT ** script;

> to be able to say

> script = & _script;

> The & operator is needed to get the address of '_script' because you write
> that you want to make the local variables point to the functions
arguments.

> The same holds for the next function argument. It's of type
> programlist_struct *, so the type of a variable to store a pointer to it
> needs to be programlist_struct **. Thus you will habe to define 'rec' as

> programlist_struct ** rec;

> and assign the address of the second function argument by using

> rec = & _rec;

> I don't understand why you want to do this but if you need to do exactly
> what you're writing that's the way to go. But I suspect you actually want
> to do something different, e.g. make copies of the structure to which
> you pass pointers to the function. In this case your variable definitions
> would be ok, but then you would have to write e.g.

> script = * _script;
> rec = * _rec;

> (using that whole structures can be copied by assignment and assuming that
> VREC_STRUCT and programlist_struct actually are typedef'ed structures...).

>                                        Regards, Jens

Jens,

Thank you so much for explaining why and how. Your reply is a lesson well
learned.

Thank you again,
jt



Wed, 29 Dec 2004 05:45:28 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Help - I need to set variable A = value held in variable named in variable B

2. non-novice needs help with variable arguements va_arg to a function

3. How to use (pointer to function), and function and pointer to (pointer to function)

4. Newbie - function pointers to variable-argument-number function

5. Need help for writing a function returning pointer

6. HELP NEEDED : passing pointers to functions

7. function pointer help needed (again)

8. Function pointer array help needed

9. function pointer help needed

10. Need help in function pointer problem in C++

11. (HELP NEEDED!)calling conventions / function pointers

12. (HELP NEEDED!)calling conventions / function pointers

 

 
Powered by phpBB® Forum Software