Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pointers with IAR (for msp430) c compiler help

Status
Not open for further replies.

m_t_blind

Newbie level 5
Joined
Jul 31, 2005
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,376
error[pe513]

Hello i have a problem whith pointers in
"IAR C Compiler for MSP430 V2.21B/W32 [Kickstart] (2.21.2.2)":

I have a pointer of type unsigned char.(unsigned char *p)
I try to assign it an address.(p = 0x0192)
(i try p = (unsigned short int)0x0192)

I get the error message :

Error[Pe513]:a value of type "int" cannot be assigned to an entity of type "unsigned char*"

or

Error[Pe513]:a value of type "unsigned short" cannot be assigned to an entity of type "unsigned char*"

The program is compiled for msp430f149
Why ????
 

iar pointer

YOU SHOULD BE HAPPY THAT THE COMPILER COMPLAINS!!!

Well yes you will have the problem with all compilers

this is not right
p = (unsigned short int)0x0192)

if you have a pointer declared as unsigned char *p and want to point to the adress 0x0192
do this

p = (unsigned char *) 0x0192 ; and if you want to get the byte of data contained at that address do this

val = * (unsigned char *) 0x0192 ;

very simple ..You have to CAST the number 0x0192 to be a pointer address otherwise is just a NUMBER in ASCII not an int ! (it has never beed declared as int). and the compiler doesn't know what you want. One thing to remember is that a pointer is not just an address but is implemented as a header with an address .specially in micronctrollers where there are a lot of memory spaces (CONST FLASH ,RAM ,EPROM etc) so sometimes you have to cast it with also the type of memory space
for example

CONST char *FLASH_PTR ;

char *myRAM_ptr .But if you want to pass the address of one to the other :
myRAM = FLASH_PTR ... the compiler (a good one ) will COPMPLAIN
 

    m_t_blind

    Points: 2
    Helpful Answer Positive Rating
iar for msp430

Thank you for your detailed answer, and the explanation on the pointers. In some books i read they dont clear this things about pointers....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top