C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Structure Initialization Posted by Plzhelp on 5 Dec 2012 at 4:34 AM
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.
CODE:
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 \n", (rst_val.ch_reg.sar));
}
END CODE.

output:
faaaaabc





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.