CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Setting a pointerred value

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hmnrobots



Joined: 02 Oct 2009
Posts: 11

View user's profile Send private message

Setting a pointerred value
PostPosted: Thu Apr 11, 2013 3:10 am     Reply with quote

Hi all
A 2 days Nightmare !
Chip is a 16f767, compiler 4.104
I declare a GLOBAL pointer:
int8 *FwdDev=0;
and a variable:
int8 d;

later then when I do:

(*FwdDev) = d;
Fprintf(HF,"\n\r RH d:%u %u Adr %u \n\r",d,*FwdDev,&FwdDev);

then I got:

RH d:177 0 Adr 80

That confirm the value of d is 177 but *FwdDev still remains null.I just don't understand!
any help please.

I even added:

*FwdDev = 5;
if(*FwdDev !=5) fprintf(HF,"\n\r No \n\r");

and I got always the answer NO
what is my mistake?
I added also #device *=16 : No success as well

sorry to disturb you with such a basic question
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Apr 11, 2013 8:58 am     Reply with quote

Post the shortest possible complete compilable code which shows the problem you're having.
Then we can all see exactly what you are doing.

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 11, 2013 11:25 am     Reply with quote

The pointer needs to point to some legitmate, allocated storage location
in RAM. Your code doesn't do that.

See the program below. One byte of RAM is allocated to the variable
'myval'. This allocation is done by the "int8 myval;" statement.
Now I can set the pointer, FwdDev, to point to myval. I do that by
taking the address of myval and putting it into FwdDev. Now it all
works. It displays 177.

The key thing you need to remember is that just simply creating a
pointer doesn't create or allocate any RAM storage locations for data.
You have a pointer, but you don't have anything for it to point to.
So to make the pointer be useful, you need to declare a variable, or
an array, and load the pointer with the address of that variable or array.
Code:

#include <16F690.h>
#fuses INTRC_IO, NOWDT, PUT
#use delay(clock=4M)   
#use rs232(baud=9600, UART1, ERRORS)

int8 *FwdDev = 0;

int8 myval;
//=================================
void main()
{
myval = 177;

FwdDev = &myval;

printf("%u \r", *FwdDev);

while(1);
}
hmnrobots



Joined: 02 Oct 2009
Posts: 11

View user's profile Send private message

PostPosted: Thu Apr 11, 2013 11:32 am     Reply with quote

JUST THANK YOU SO MUCH , at least I've got an answer and I will remember that declaring a pointer doesn't allocate any memory!

Once again Many thanks PCM Programmer to take the time to answer to such a basic question.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group