Illegal constant expression: copying address to a variable

cancel
Showing results for 
Search instead for 
Did you mean: 

Illegal constant expression: copying address to a variable

Jump to solution
613 Views
amitdhand
Contributor I

I try to compile the below mentioned code in Code-warrior 10.7 but CW throws an error "illegal constant expression"

Code:

uint32_t val1;
uint32_t val2;
uint32_t val2 = (uint32_t)&val2;            // Error is specified in this line

void main(void)
{

.   // some code

.

.

}

The expression could work out with pointers but I am importing a code from IAR Embedded Workbench to Code-warrior and in IAR Embedded Workbench there is no such problem with such an expression.

Labels (1)
0 Kudos
1 Solution
408 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Amit,

The compilers are different ,how about use like below:

uint val1;

uint *val2 = &val1; 


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
3 Replies
408 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Amit Dhand ,

I test on my side , these code can work well on my side.

pastedImage_3.png

Which chip do you used ?

I recommend you create a new project, then copy and paste these code into it , build, check whether can work.


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
408 Views
amitdhand
Contributor I

Thanks Alice_Yang for your prompt response on the query.

It is my mistake that I didn't recheck the code before posting. The problem still remains the same

Code:

 

uint32_t val1;
uint32_t val2 = (uint32_t)&val1;            // Error is specified in this line: Illegal

 

void main(void)
{

.   // some code

.

.

}

I am using MC9S12ZVCA192 chip for my project.

Screenshot from the CodeWarrior 10.7

pastedImage_5.png

0 Kudos
409 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Amit,

The compilers are different ,how about use like below:

uint val1;

uint *val2 = &val1; 


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos