Structure Initialization - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Structure Initialization

PlzhelpPlzhelp Posts: 1Member
Hi All,

I am writing a code where in I have used nested structure. All these structures are defined to be a 64 bit register. Trying to assign a value to these structures as a whole but it is not happening properly. The problem is whole value is not getting assigned. Only a part of it is getting assigned. I have pasted the code here. Please let me know how can I fix it. Thank you in advance.
[b]CODE:
[size=3]Header file:
struct SARx
{
unsigned long SAR;
};
struct CHNL_reg
{
struct SARx sar;
};
struct dma_reg
{
struct CHNL_reg ch_reg;
};

C File:
struct dma_reg rst_val;
unsigned long *ptr;
main()
{
ptr = (unsigned long) &(rst_val.ch_reg.sar);
*ptr=(unsigned long)0x0ffffaaaaabc;
printf(" %x
", (rst_val.ch_reg.sar));
}
END CODE.[/size]
output:
faaaaabc[/b]

Sign In or Register to comment.