Searching \ for '[OT:] C pointer conversion problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/language/index.htm?key=c
Search entire site for: 'C pointer conversion problem'.

Exact match. Not showing close matches.
PICList Thread
'[OT:] C pointer conversion problem'
2004\08\08@160907 by Thomas

picon face
Hi,
I have a "suspicious pointer conversion" warning from
the MCC18 compiler.  The warning is at the line
"OSCreateTask(test)" below:

#include <p18f8720.h>
struct TCB_t {
   long    (*fnc_ptr)(void);
} TCBs[5];

#pragma code testloc=0x01fff0
void test (void){_asm NOP _endasm}
#pragma code

void OSCreateTask( long (*Fnc_Ptr)(void) ) {
   TCBs[0].fnc_ptr = Fnc_Ptr;
}
void OSStart(void) {
   long (*fncn_temp)(void);

   fncn_temp=TCBs[0].fnc_ptr;
   (*fncn_temp)();             // run
}
void main (void)
{
   OSCreateTask(test);   // <= the warning is here
   OSStart();
   while (1);
}

Is this warning serious?  Will my code run properly if
I just ignore it?  I notice that if I replace the
"void test (void)" with a "long test (void)", the
problem seems to go away.  I don't want to do this,
however, because my test function doesn't return any
useful value, so ideally, I want to keep it as "void
test (void)".  Is there any way around this?

Regards,
Thomas



__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2004\08\08@222944 by john chung

flavicon
face
Thomas wrote:

{Quote hidden}

    Expected return value must be treated VERY seriously.

>I just ignore it?  I notice that if I replace the
>"void test (void)" with a "long test (void)", the
>
>
   B'cos OSCreateTask() expected a pointer to a function of no argument
which returns long. Therefore you have to supply a function that has the
same
arguments and return value.

>problem seems to go away.  I don't want to do this,
>however, because my test function doesn't return any
>useful value, so ideally, I want to keep it as "void
>test (void)".  Is there any way around this?
>
>

   change the OSCreateTask to (void (*pfc)(void)); Also note that
you have to change the pfunction in the structure too.



John

{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamKILLspammitvma.mit.edu

2004\08\08@223400 by Anthony Toft

flavicon
face
> #pragma code testloc=0x01fff0
> void test (void){_asm NOP _endasm}
> #pragma code


first glance says that the function declaration should be

long test(void){_asm NOP _endasm}

to match the type you specified.
--
Anthony Toft <.....toftatKILLspamspam.....cowshed.8m.com>

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu

2004\08\09@023555 by Thomas

picon face
>     change the OSCreateTask to (void (*pfc)(void));
> Also note that
> you have to change the pfunction in the structure
> too.
Sorry I have no clue what the pfunction should look
like in the structure.  It can't be "(void
(*pfc)(void))", can it?  I must have a type long
variable to hold the address of a function, which can
be at 0x1FFFF.



__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\08\09@024632 by Thomas

picon face
It looks like I have to change
"OSCreateTask(long(*Fnc_Ptr)(void))" to
"OSCreateTask(void(*Fnc_Ptr)(void))" for it to match
with the "test" function.  However, after I did it, it
has problem assigning a void pointer to a long
variable:

struct TCB_t {
   long    (*fnc_ptr)(void);
} TCBs[5];

void OSCreateTask( void (*Fnc_Ptr)(void) ) {
   TCBs[0].fnc_ptr = Fnc_Ptr;  //<= PROBLEM!
}

I need a long variable to be able to hold the address
up to 0x1FFFF.
Regards,
Thomas
--- Anthony Toft <toftatspamspam_OUTCOWSHED.8M.COM> wrote:

{Quote hidden}

__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\08\09@030502 by Chris Emerson

flavicon
face
On Sun, Aug 08, 2004 at 11:46:30PM -0700, Thomas wrote:
> It looks like I have to change
> "OSCreateTask(long(*Fnc_Ptr)(void))" to
> "OSCreateTask(void(*Fnc_Ptr)(void))" for it to match
> with the "test" function.  However, after I did it, it
> has problem assigning a void pointer to a long
> variable:
>
> struct TCB_t {
>     long    (*fnc_ptr)(void);
> } TCBs[5];
>
> void OSCreateTask( void (*Fnc_Ptr)(void) ) {
>     TCBs[0].fnc_ptr = Fnc_Ptr;  //<= PROBLEM!
> }
>
> I need a long variable to be able to hold the address
> up to 0x1FFFF.

You're a bit confused about the (admittedly quite confusing) C
declaration syntax.

In:

long (*foo)(void);

foo is a pointer to a function taking nothing and returning long.  The
"long" is part of the function signature, not anything to do with the
size of foo itself.

void (*foo)(void);

is what you want.  It declares foo to be a pointer to a function taking
nothing (void) and returning nothing.  The pointer should be the right
size.

Chris

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\08\09@031952 by john chung

flavicon
face
Thomas wrote:

>It looks like I have to change
>"OSCreateTask(long(*Fnc_Ptr)(void))" to
>"OSCreateTask(void(*Fnc_Ptr)(void))" for it to match
>with the "test" function.  However, after I did it, it
>has problem assigning a void pointer to a long
>variable:
>
>struct TCB_t {
>    long    (*fnc_ptr)(void);
>} TCBs[5];
>
>void OSCreateTask( void (*Fnc_Ptr)(void) ) {
>    TCBs[0].fnc_ptr = Fnc_Ptr;  //<= PROBLEM!
>}
>
>
>
   if you really MUST need :

       struct TCB_t {
           long    (*fnc_ptr)(void);
       } TCBs[5];

 then you have to use "long" from the beginning to the end but
there is a workaround........ Please don't go there........
From my understanding is that you need to return a value from
"fnc_ptr" which is 0x1ffff. Here goes..........

here is an example:

struct TCB_t {
   long    (*fnc_ptr)(void);
} TCBs[5];

#pragma code testloc=0x01fff0           //i assume that the function starts at this address
void test (void){return 0;}
#pragma code

void OSCreateTask( void (*Fnc_Ptr)(void) ) {
   TCBs[0].fnc_ptr = (long (*)(void))Fnc_Ptr; //must change the type......... or the compiler complains.
}

//starts the OS.
void OSStart(void) {
   long (*fncn_temp)(void);    //declaration
   fncn_temp=TCBs[0].fnc_ptr;  //now points to test()
   (*fncn_temp)();             //run....... But fncn_temp must return long BUT you run test() which returns void!
}
void main (void)
{
   OSCreateTask(test);
   OSStart();
   while (1);
}

in short the code can work must it is a very very bad idea..................


>I need a long variable to be able to hold the address
>up to 0x1FFFF.
>Regards,
>
>
   No sure what u mean here. The function pointer can hold the address
to that range. You don't
need a long variable

John

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\08\09@123704 by Thomas

picon face
Thank you everyone for your help!  I think it finally
do what I want.  Here it is:

#include <p18f8720.h>
struct TCB_t {
   void (*fnc_ptr)(void);
} TCBs[2];

#pragma code testloc=0x01fff0
void test (void){_asm NOP _endasm}
#pragma code

void OSCreateTask( void (*Fnc_Ptr)(void) ) {
   TCBs[0].fnc_ptr = Fnc_Ptr;
}
void OSStart(void) {
   void (*fncn_temp)(void);

   fncn_temp=TCBs[0].fnc_ptr;
   (*fncn_temp)();             // run
}
void main (void)
{
   OSCreateTask(test);
   OSStart();
   while (1);
}

> You're a bit confused about the (admittedly quite
confusing) C declaration syntax.

You are right on this!

Regards,
Thomas




__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...